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

Newbie Question: if Property1 or Property2 or Property3 ?


Reply

5 Posts   867 Views

Avatar
tonito

24 August 2010 at 3:33am Community Member, 24 Posts

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 ?

Avatar
swaiba

24 August 2010 at 6:59am Forum Moderator, 1796 Posts

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!

Avatar
tonito

24 August 2010 at 3:31pm (Last edited: 24 August 2010 3:34pm), Community Member, 24 Posts

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.

Avatar
swaiba

24 August 2010 at 7:28pm Forum Moderator, 1796 Posts

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?

Avatar
tonito

29 August 2010 at 2:31pm Community Member, 24 Posts

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.