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

Avatar
prawnstar

2 July 2010 at 12:01pm (Last edited: 2 July 2010 12:17pm), Community Member, 116 Posts

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

2 July 2010 at 12:24pm (Last edited: 2 July 2010 12:35pm), Community Member, 33 Posts

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

Avatar
prawnstar

2 July 2010 at 1:08pm Community Member, 116 Posts

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

2 July 2010 at 1:28pm Community Member, 116 Posts

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

This works fine:

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

Chris.b

Avatar
Willr

2 July 2010 at 4:37pm Forum Moderator, 5511 Posts

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