Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Accessing variables in templates

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: 927 Views
  • sav_ss
    Avatar
    Community Member
    11 Posts

    Accessing variables in templates Link to this post

    Hi,

    I have a question about accessing variables in templates.
    If I have classes Foo & Bar

    class Foo extends Page
    {
    static $db = array(
    'ContainedItem' => 'Bar'
    );
    }

    class Bar extends Page
    {
    static $db = array(
    'MyDate' => 'Date'
    );
    }

    I would like to know how to get at MyDate from Foo.ss
    ... along the lines of

    <% if Bar %>
    <% control Bar %>
    ???? <- Here I want to do a comparison with the current date (if CurrentDate < MyDate) unsure how to do that also.
    <% end_control %>
    <% end-if %>

    Any help you can offer would be greatly appreciated.

    Regards,

    Scott

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: Accessing variables in templates Link to this post

    Hi Scott,

    Firstly this would live inside the template section (but that is me being picky)...

    how about this...
    (note all untested)

    <% if ContainedItem %>
    <% control ContainedItem %>
    <% if MyDate > Now %>
    MyDate ({$MyDate}) is large than current date ({$Now})
    <% end_if %>
    <% end_control %>
    <% end_if %>

  • sav_ss
    Avatar
    Community Member
    11 Posts

    Re: Accessing variables in templates Link to this post

    Hi, and thank you so much for the response. I hadn't even scrolled down the Forums main page far enough to see the templates section ... heh. I'll move over there.

    Regards,

    Scott

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