17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2583 Views |
-
Dynamic copyright year

6 February 2008 at 11:05am
Howdy,
I thought I'd try to throw in some php for the year to be dynamic just to complicate things. But it doesn't want to work.
This is what I tried:
<p>Copyright © <?php echo date("Y"); ?></p>
And this is the error I got:
Parse error: syntax error, unexpected T_ECHO in /tmp/silverstripe-cache-home-popraux-public_html/.cache.home.popraux.public_html.themes.popraux.templates.Page.ss on line 85Do I need do use a certain control or varialble for this to work?
-
Re: Dynamic copyright year

6 February 2008 at 11:17am
<p>Copyright © $Now.Year</p>
You can't use PHP in templates. (:
-
Re: Dynamic copyright year

6 February 2008 at 11:41am
Yeah. After I did it I figured that was the case.
So how about a random array of variables? I'm hijacking my own thread but considering I can't do PHP in a template would I have to put the code to generate the random array in Page.php and use it's variables in the template?
-
Re: Dynamic copyright year

6 February 2008 at 2:36pm
Make a method in either Page or Page_Controller, which returns the random value, and call it frm the template, using $Methodname
-
Re: Dynamic copyright year

8 February 2008 at 5:00am
Does anyone know how I could make Template Variables like $Now.Year work in the Content Field of Pages? So that it is replaced when I write in $Now.Year in a pages Content. That would be quite cool!
cheers
-
Re: Dynamic copyright year

8 February 2008 at 11:03am Last edited: 8 February 2008 11:07am
Found a solution ..
if you ever want to parse PHP via Template Tags inside $Content you could do the following:
class Page_Controller extends ContentController {
....
function ContentProcessed(){
$s = new SSViewer_FromString($this->data()->getField("Content"));
return $s->process($this);
}....
}
if you now use $ContentProcessed in your Page.ss you can enter template variables in the CMS. $Now.Year in the "Content" Html Editor Field would turn into 2008 or whatever year we are on the Website. There may be something more elegant (thinking $Content.Processed ..?) but this works pretty well.
Hope that helps someone someday
-
Re: Dynamic copyright year

9 February 2008 at 7:32pm
Extending that example a bit, you could also do this instead of your return line:
return DBField::create("HTMLText", $s->process($this));That way, you can do things like $ContentProcessed.XML or $ContentProcessed.Summary in your template.
| 2583 Views | ||
|
Page:
1
|
Go to Top |



