Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » InSection Questions

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

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

Page: 1
Go to End
Author Topic: 2632 Views
  • Liam
    Avatar
    Community Member
    470 Posts

    InSection Questions Link to this post

    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 %>

  • vstrazz
    Avatar
    Community Member
    63 Posts

    Re: InSection Questions Link to this post

    try this

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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: InSection Questions Link to this post

    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 %>

  • contigo
    Avatar
    Community Member
    16 Posts

    Re: InSection Questions Link to this post

    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

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: InSection Questions Link to this post

    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.

    2632 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.