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.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

InSection Questions


Reply

5 Posts   2654 Views

Avatar
Liam

9 August 2008 at 7:47am Community Member, 470 Posts

I'm guessing it is not possible to check multiple pages using InSection? e.g if InSection(page1,page2)

Is it then possible to use if/else if statements in my template with it? I tried with no luck.

<% if InSection(page) %>
Something
<% else_if InSection(page2) %>
Something else
<% end_if %>

Avatar
vstrazz

9 August 2008 at 8:34am Community Member, 63 Posts

try this

<% if URLSegment== page title %>
content here
<% else_if URLSegment== page title 2 %>
more content
<% end_if %>

Avatar
Willr

9 August 2008 at 10:02pm Forum Moderator, 5511 Posts

I would have thought your (Lee's) code would work. Does something like this work?

<% if InSection(a) %>
<% else %>
<% if InSection(b) %>
<% end_if %>
<% end_if %>

Avatar
contigo

11 August 2008 at 9:05am (Last edited: 11 August 2008 4:59pm), Community Member, 16 Posts

I just had the same issue as LeeUmm while using SS v2.2.2. I found a possible bug in sapphire/core/SSViewer.php and a fix.

Around line 263 in SSViewer.php you'll find several ereg_replace() calls that appear to change the .ss template if/else syntax to php if/else syntax. There are a few lines that replace "else_if" wrong or not at all...

// line 278
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *&&? *([A-Za-z0-9_]+) +%' . '>', '<? else_if($item->hasValue("\\1") && $item->hasValue("\\2")) { ?>', $content);
//change to
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *&&? *([A-Za-z0-9_]+) +%' . '>', '<? } else if($item->hasValue("\\1") && $item->hasValue("\\2")) { ?>', $content);

// line 274
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *\\|\\|? *([A-Za-z0-9_]+) +%' . '>', '<? else_if($item->hasValue("\\1") || $item->hasValue("\\2")) { ?>', $content);
// change to
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *\\|\\|? *([A-Za-z0-9_]+) +%' . '>', '<? } else if($item->hasValue("\\1") || $item->hasValue("\\2")) { ?>', $content);

// line 266
$content = ereg_replace('<' . '% +if +([A-Za-z0-9_]+)\\(([A-Za-z0-9_-]+)\\) +%' . '>', '<? if($item->hasValue("\\1",array("\\2"))) { ?>', $content);
// ADD this line below it...
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+)\\(([A-Za-z0-9_-]+)\\) +%' . '>', '<? } else if($item->hasValue("\\1",array("\\2"))) { ?>', $content);

// line 263
$content = ereg_replace('<' . '% +if +([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+) +%' . '>', '<? if($item->obj("\\1",null,true)->hasValue("\\2")) { ?>', $content);
// ADD this line below it...
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+) +%' . '>', '<? } else if($item->obj("\\1",null,true)->hasValue("\\2")) { ?>', $content);

Keep in mind this changes core code. Any upgrades to SS will erase these changes. By then this bug might be fixed anyway :). I will try to look in the bug reports to see if it's there already, and if not add it.

Oh, and Willr's suggestion works for me, I just wanted to have the ability to make my templates a bit more readable.

-Billy

Avatar
Liam

12 August 2008 at 11:32am Community Member, 470 Posts

Great find and fix. I haven't had time to apply changes, just viewing the topic for the first time since posting with the weekend and all.

Submitting the bug would be great, as I'm like you, I'd rather have cleaner more proper code in my templates, and having to update all my SS sites in the future would be a hassle.