Jump to:

3402 Posts in 979 Topics by 855 members

Template Questions

SilverStripe Forums » Template Questions » Multiple ||

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

Page: 1 2
Go to End
Author Topic: 1437 Views
  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Multiple || Link to this post

    On a template I want to display some text if anyone of four conditions are meet ie

    <% if Referrals || Supervision || Consultation || Review %>

    but I can do this as I can only have 2 conditions. I can't see a way t o nest the conditions so how do I test for this?

    Know this has got to be an easy answer but I am stumped.

    Thanks

    Catherine

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Multiple || Link to this post

    No the template language does not support that. In order to get that to work you could write a small PHP function which does the or comparison. Like

    // in say page.php but could be your own page type
    function IfSomething() {
    return ($this->Referrals || $this->Supervision || $this->Consultation || $this->Review) ? true : false;
    }

    <% if IfSomething %>....

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Multiple || Link to this post

    Hi Will

    Thanks for this, realised I shouldn't have been looking for that kind of function in a tempalte this morning

    Cheers

    Catherine

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Multiple || Link to this post

    Ok so I am stumped. I have added to DirectoryPage.php in the DirectoryPage_Controller section

    class DirectoryPage_Controller extends Page_Controller {
       
       ...

    function Offerings() {
    return True;
    }
       
    }
    (I have removed the actual decision logic for now as I just can't get the function to apply)

    and to DirectoryPage.ss I have added

    <% if Offerings %>
       <li>Avaliable <% end_if %> ...

    but Avaliable does not display. I know its got to be simple but what am I doing wrong?

    Thanks

    Catherine

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Multiple || Link to this post

    Try moving it to the DirectoryPage class rather then the controller, Or move that function to the page controller in Page.php and see if it picks the function up in either of those 2 places (you might want to put a die(); statement in the function so you can obviously tell when the function is called.

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Multiple || Link to this post

    Tried both page.php and the DirectoryPage section of DirectoryPage.php neither worked. If I put die(); inside another function on DirectoryPage it works but not for Offerings.

    For some reason it is this function no applying. Have tried to using flush and saving the page again in the CMS but to no avail. Any other suggestions?

    Thanks

    Catherine

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Multiple || Link to this post

    Strange. Perhaps try changing the function name to getOfferings() and leaving the template if as <% if Offering %>.

    You aren't inside a control or any other loop on the DirectoryPage.ss are you?

  • mschiefmaker
    Avatar
    Community Member
    187 Posts

    Re: Multiple || Link to this post

    Yes I am inside a control. ?

    1437 Views
Page: 1 2
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.