Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Newbie Question: if Property1 or Property2 or Property3 ?

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

Page: 1
Go to End
Author Topic: 860 Views
  • tonito
    Avatar
    Community Member
    24 Posts

    Newbie Question: if Property1 or Property2 or Property3 ? Link to this post

    I am trying the following in my templates:

             <% if Property1 or Property2 or Property3 %>
             hello
             <% end_if %>

    but it seems to crash the site. Any idea for an unlimited or conditional statement ?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Newbie Question: if Property1 or Property2 or Property3 ? Link to this post

    help -> documentation -> Level 2: SilverStripe fundamentals -> Templates -> If blocks

    or here --> http://doc.silverstripe.org/templates#if_blocks

    or "same as php"

    Hope this helps!

  • tonito
    Avatar
    Community Member
    24 Posts

    Re: Newbie Question: if Property1 or Property2 or Property3 ? Link to this post

    Thank you for pointing that documentation page out.

    I guess I can always do nested conditional statements or use a CheckboxSetField.

    However, it seems that what is possible in php (http://forums.digitalpoint.com/showthread.php?t=175713) is not necessarily possible with Silverstripe. This is cumbersome in my case because I would like to check if many variables exist at once.

    I get a blank page in my templates with:

    <% if Checkbox1 || Checkbox2 || Checkbox3 %>
    Hello
    <% end_if %>

    With Checkbox1, Checkbox2 and Checkbox3 each as Boolean CheckboxField.

    I also get a blank page with:
    <% if Text1 = Hello && Text2 = Hello %>
    Hello
    <% end_if %>

    With Text1 and Text2 as Varchar.

    This is with Mamp and SS 2.4.0.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Newbie Question: if Property1 or Property2 or Property3 ? Link to this post

    Hi tonito,

    It has been mentioned many times that templates should be simple and readable.

    Maybe defining a PHP function like...

    function AnyOfThreeSettingsTrue()
    {
    return ($this->Setting1 || $this->Setting2 || $this->Setting3);
    }

    and using that...

    <% if AnyOfThreeSettingsTrue %>
    Do Stuff
    <% end_if %>

    ..might help?

  • tonito
    Avatar
    Community Member
    24 Posts

    Re: Newbie Question: if Property1 or Property2 or Property3 ? Link to this post

    Thank you for your help. I realize how basic a question this is.

    I agree about the templates, they should be readable.

    The problem I have with SS, now that I am developing a more complex website, is that it requires a clear grasp of php, but php is totally foreign to me.

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