Jump to:

3392 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Nesting an IF in a control

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

Page: 1
Go to End
Author Topic: 1042 Views
  • ssssteve
    Avatar
    Community Member
    4 Posts

    Nesting an IF in a control Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Nesting an IF in a control Link to this post

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

  • ssssteve
    Avatar
    Community Member
    4 Posts

    Re: Nesting an IF in a control Link to this post

    Ta!

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