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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Date in footer using $Now var


Reply


5 Posts   1761 Views

Avatar
prawnstar

Community Member, 127 Posts

2 July 2010 at 12:01pm

Edited: 02/07/2010 12:17pm

I'm trying to update the copyright year in my sites footer dynamically by simply echoing the current year using the $Now var like this:

$Now.format(Y)

I'm using the $Now var in my my Footer.ss file which is an included file from the templates/includes folder, on multiple pages by means of a public function call from the Pages.php controller.

The $now var doesn't seem to work when the template is called as an include, but it works fine if I just use it in the template that's calling the include.

Any ideas are appreciated.

Chris.b

Avatar
sonet

Community Member, 33 Posts

2 July 2010 at 12:24pm

Edited: 02/07/2010 12:35pm

$Now.Year works in includes. Don't forget to flush the cache with http://localhost/?flush=1

Avatar
prawnstar

Community Member, 127 Posts

2 July 2010 at 1:08pm

Hmmm...

I just tried $Now.Year and it didn't work either. So I played a bit with the Footer.ss include and as it turns out
neither method works inside:

<% if GetFooter %>
<% control GetFooter %>
-- Footer code here --
<% end_control %>
<% end_if %>

Chris.b

Avatar
prawnstar

Community Member, 127 Posts

2 July 2010 at 1:28pm

Specifically it's the <% control GetFooter %> part.

This works fine:

<% if GetFooter %>
-- Footer code here --
<% end_if %>

Chris.b

Avatar
Willr

Forum Moderator, 5513 Posts

2 July 2010 at 4:37pm

Its because $Now is part of the Page scope, not your GetFooter scope. If you're inside the GetFooter you'll need to use <% control Top %>$Now.Year<% end_control %>