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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

Accessing variables in templates


Go to End


3 Posts   1311 Views

Avatar
sav_ss

Community Member, 11 Posts

13 January 2011 at 5:29pm

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

Avatar
swaiba

Forum Moderator, 1899 Posts

14 January 2011 at 3:44am

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

Avatar
sav_ss

Community Member, 11 Posts

18 January 2011 at 12:45pm

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