Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.


Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Dynamic copyright year


7 Posts   2802 Views


6 February 2008 at 11:05am 74 Posts


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 &copy; <?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/ on line 85

Do I need do use a certain control or varialble for this to work?


6 February 2008 at 11:17am Forum Moderator, 474 Posts

<p>Copyright &copy; $Now.Year</p>

You can't use PHP in templates. (:


6 February 2008 at 11:41am 74 Posts

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?


6 February 2008 at 2:36pm Forum Moderator, 474 Posts

Make a method in either Page or Page_Controller, which returns the random value, and call it frm the template, using $Methodname


8 February 2008 at 5:00am Community Member, 10 Posts

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!



8 February 2008 at 11:03am (Last edited: 8 February 2008 11:07am), Community Member, 10 Posts

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 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


9 February 2008 at 7:32pm Core Development Team, 84 Posts

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.