Jump to:

22980 Posts in 11761 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Date in footer using $Now var

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

Page: 1
Go to End
Author Topic: 1436 Views
  • prawnstar
    Avatar
    Community Member
    116 Posts

    Date in footer using $Now var Link to this post

    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

  • sonet
    Avatar
    Community Member
    33 Posts

    Re: Date in footer using $Now var Link to this post

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

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: Date in footer using $Now var Link to this post

    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

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: Date in footer using $Now var Link to this post

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

    This works fine:

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

    Chris.b

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Date in footer using $Now var Link to this post

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

    1436 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.