3212 Posts in 847 Topics by 809 members
| Go to End | Next > | |
| Author | Topic: | 8810 Views |
-
if and else_if with InSection()

25 March 2009 at 8:43am
Gentlemen,
Why isn't this working?
<% if InSection(home) %>
<img src="themes/BrightSide1/images/header.jpg" width="820" height="308" alt="headerphoto" class="no-border" />
<% else_if InSection(services) %>
<img src="themes/BrightSide1/images/header_services.jpg" width="820" height="180" alt="headerphoto" class="no-border" />
<% else %>
<img src="themes/BrightSide1/images/headerphoto.jpg" width="820" height="180" alt="headerphoto" class="no-border" /><% end_if %>
Here's what I want to do: I have a large header photo for the home page (that works)
Then, I want some pages to have a different header photo (services, about us and team)
I also want a fall-back photo for all the other pages (hence the final else statement)Thanks for your help!
-
Re: if and else_if with InSection()

25 March 2009 at 3:06pm
Strange.
Appears to be the else_if statement not liking having a method call as a condition.
I tried this and it worked fine:
<% if InSection(home) %>
Home
<% else_if 1 %>
Test
<% else %>
Not Either Page
<% end_if %>Check this out: http://www.silverstripe.org/archive/show/138468#post138468.
Quick ugly hack:
<% if InSection(home) %>
<img src="themes/BrightSide1/images/header.jpg" width="820" height="308" alt="headerphoto" class="no-border" />
<% else %>
<% if InSection(services) %>
<img src="themes/BrightSide1/images/header_services.jpg" width="820" height="180" alt="headerphoto" class="no-border" />
<% else %>
<img src="themes/BrightSide1/images/headerphoto.jpg" width="820" height="180" alt="headerphoto" class="no-border" />
<% end_if %>
<% end_if %>Aaron
-
Re: if and else_if with InSection()

26 March 2009 at 7:20am
Thanks, that worked. It's ugly though ... especially if you have multiple "if" statements.
-
Re: if and else_if with InSection()

26 March 2009 at 8:28am
Yup, see the link for how someone else fixed it without the template-side hack.
Perhaps a bug report was never raised on this, so you might want to add it yourself.
Cheers
Aaron -
Re: if and else_if with InSection()

27 March 2009 at 2:23am Last edited: 27 March 2009 2:24am
Hi,
Background on this: Template code parsing is done in sapphire/core/SSViewer.php. The function parseTemplateContent runs template code through a series of regular expressions which replace template code constructs with PHP code. These regular expressions support an arbitrary combination of call signatures. The call you are trying to make isn’t one of the supported call syntaxes.
A patch has been submitted for testing which would remove these arbitrary constraints. So, code like <% else_if Call1(Arg1) %> should work. Would you have time to help test this patch?
Thank you,
Ben -
Re: if and else_if with InSection()

27 March 2009 at 9:01am
Cheers Ben,
Just downloaded patch revision5 and applied to my SVN. Will test a few things over the weekend and recomment my bug submission.
Thanks again
Aaron -
Re: if and else_if with InSection()

27 March 2009 at 9:13am
Thanks, Aaron! Please let me know what you find.
Ben
| 8810 Views | ||
| Go to Top | Next > |


