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.

Template Questions /

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

Nesting an IF in a control


Go to End


3 Posts   2055 Views

Avatar
ssssteve

Community Member, 4 Posts

22 February 2009 at 1:10pm

Is it possible to use a conditional if to check a date, such as:

  <% control Children %>
     <% if EventDate > Now %>
        <li>$Title</li>
     <% end_if %>
  <% end_control %>

Embargo/Expiry doesn't seem to limit my list of events (even logged out), so I need to filter them another way.

Avatar
Willr

Forum Moderator, 5523 Posts

23 February 2009 at 2:07pm

the template parser is basic, you can't do comparisons between 2 variables. You will have to add a function to your Event then check on that

function ShowEvent() {
return ($this->EventDate > date('Y-m-d')) ? true : false;
}

then in your template use <% if ShowEvent %>

Avatar
ssssteve

Community Member, 4 Posts

23 February 2009 at 9:18pm

Ta!