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 ?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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 ?
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!
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.
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?
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.