21309 Posts in 5738 Topics by 2603 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 678 Views |
-
Newbie Question: if Property1 or Property2 or Property3 ?

24 August 2010 at 3:33am
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 ?
-
Re: Newbie Question: if Property1 or Property2 or Property3 ?

24 August 2010 at 6:59am
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!
-
Re: Newbie Question: if Property1 or Property2 or Property3 ?

24 August 2010 at 3:31pm Last edited: 24 August 2010 3:34pm
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.
-
Re: Newbie Question: if Property1 or Property2 or Property3 ?

24 August 2010 at 7:28pm
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?
-
Re: Newbie Question: if Property1 or Property2 or Property3 ?

29 August 2010 at 2:31pm
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.
| 678 Views | ||
|
Page:
1
|
Go to Top |


