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

Accessing variables in templates


Reply

3 Posts   951 Views

Avatar
sav_ss

13 January 2011 at 5:29pm Community Member, 11 Posts

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

14 January 2011 at 3:44am Forum Moderator, 1796 Posts

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

18 January 2011 at 12:45pm Community Member, 11 Posts

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