3217 Posts in 853 Topics by 812 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 6268 Views |
-
double IF conditions

25 December 2008 at 3:57am Last edited: 25 December 2008 3:59am
Hi everyone,
I have a big problem with double if conditions, when I try to use something like
<% if ClassName != ForumHolder && ClassName != Forum %>
do something
<% else %>
blablabla
<% end_if %>or
<% if (ClassName != ForumHolder) && (ClassName != Forum) %>
do something
<% else %>
blablabla
<% end_if %>or other variants with quotes, double quotes or any without brackets - I have an error like
syntax error, unexpected '}' in ...
Is it unreal to use double conditions in templates or there is something I don't know about? How can I solve this?
-
Re: double IF conditions

25 December 2008 at 6:04am
The template syntax is pretty basic and can't do what you're after.
Scroll down on this page to see http://doc.silverstripe.com/doku.php?id=templates
I'd suggest using else_if or nesting them if possible. Hackish I know, but that's about it.
-
Re: double IF conditions

25 December 2008 at 6:50am
Yeah, I done this before, but it's very ugly! Btw - there IS example of double conditions on wiki page, but it's just not working
-
Re: double IF conditions

27 December 2008 at 10:55pm
I think the only double if that works (at least it did once ;) ) is in the form of:
<% if Property || Property2 %> or <% if Property && Property2 %>
so not when evaluating them against other values.
-
Re: double IF conditions

5 January 2009 at 6:49pm Last edited: 5 January 2009 7:51pm
Yes as dio5 said, it won't work with multiple expressions when evaluating against values, what I do is make functions in the controller to return true or false example:
Controller:
public function IsForumSection()
{
switch($this->ClassName) {
case 'ForumHolder':
case 'ForumPage':
return true;
break;
default:
return false;
}
}Template:
<% if IsForumSection %>
do something
<% else %>
blablabla
<% end_if %>This way you can call multiple expressions and have the logic as complex as you like...
-
Re: double IF conditions

6 February 2009 at 1:46pm
I have seen this in the wiki:
<% if Property %>
... optional content ...
<% else_if OtherProperty %>
... alternative content ...
<% else %>
... alternative content ...
<% end_if %>So I tried this:
<% control Top %>
<% if InSection(section1) %>
<% include File1 %>
<%else_if InSection(section2) %>
<% include File2 %>
<% else %>
<% include File3 %>
<% end_if %>
<% end_control %>However the esle_if does not seem to work. Instead if the first one evaluates to true, the <% else_if InSection(section2) %> gets printed in the output as a string after the file is included. If the first one is false and the second one is supposed to be true the last file gets included.
I am using the Trunk version of 2.3 downloaded via SVN 2/5/2009.
-
Re: double IF conditions

6 February 2009 at 1:56pm
Your logic must be in the controller and not the template, also you cannot pass attributes to the template functions that way just make separate functions in the controller.
Another option is to use your page types as in ClassName == 'NewsPage' etc.... this does work
HTH
| 6268 Views | ||
|
Page:
1
|
Go to Top |





