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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Date in footer using $Now var


Go to End


5 Posts   3681 Views

Avatar
digibrains

Community Member, 130 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
digibrains

Community Member, 130 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
digibrains

Community Member, 130 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, 5523 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 %>