Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » SS 3.0.3 - Loop children not limited to children of current page - SOVLED

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

Page: 1
Go to End
Author Topic: 2195 Views
  • Thomashv
    Avatar
    Community Member
    32 Posts

    SS 3.0.3 - Loop children not limited to children of current page - SOVLED Link to this post

    I'm testing out SilverStripe 3.0.3, and I find the side behaving strange. I see that the code has changed in the simple template from using <% loop menu(2) %> to using <% loop $Children %>

    Anyway, the result is that I get all children of every page showing up on everypage with children. Is there any bugs in the built in template controls? I mean loop children should normally only loop through the children of the specific page?

    This is the new SidebarMenu simple template code:

    <%--Include SidebarMenu recursively --%>
    <% if $Children %>
       <% loop $Children %>
          <li class="$LinkingMode">
             <a href="$Link" class="$LinkingMode" title="Go to the $Title.XML page">
                <span class="arrow">&rarr;</span>
                <span class="text">$MenuTitle.XML</span>
             </a>

             <% if $Children %>
                <ul>
                   <% include SidebarMenu %>
                </ul>
             <% end_if %>

          </li>
       <% end_loop %>
    <% end_if %>

  • Thomashv
    Avatar
    Community Member
    32 Posts

    Re: SS 3.0.3 - Loop children not limited to children of current page - SOVLED Link to this post

    I found that in the SideBar.ss include it is defined a loop through $Menu(1) for the SidebarMenu.ss include. Like this:

    <aside>
       <% if $Menu(2) %>
          <nav class="secondary">
             <h3>
                <% loop $Level(1) %>
                   $Title
                <% end_loop %>
             </h3>
             <ul>
                <% loop $Menu(1) %>
                   <% include SidebarMenu %>
                <% end_loop %>
             </ul>
          </nav>
       <% end_if %>
    </aside>

    That is why the sidebar menu shows the children of all of the first level pages instead of showing only the children of the current page as we are used to in SilverStripe. I don't know if this are some kind of a new idea or just a mistake, but to get it work as I intended I just deleted the loop around the <% include SidebarMenu %>. Just like this:

    <aside>
       <% if $Menu(2) %>
          <nav class="secondary">
             <h3>
                <% loop $Level(1) %>
                   $Title
                <% end_loop %>
             </h3>
             <ul>
                <% include SidebarMenu %>
             </ul>
          </nav>
       <% end_if %>
    </aside>

    Hope this could be to any help for other confused SilverStripers.

    Merry Christmas to all of you!

  • dayhox
    Avatar
    Community Member
    2 Posts
  • Bruce B
    Avatar
    Community Member
    145 Posts

    Re: SS 3.0.3 - Loop children not limited to children of current page - SOVLED Link to this post

    Just to clarify: this thread is referring to the Simple theme that is included in SS 3.
    The code that Thomashv provided is close but not quite there. It won't provide menus when you are in the child pages. The following code for SideBar.ss has been posted in github and should be in the next version. Meanwhile, here it is for anyone who has found this thread

    <aside>
       <% if $Menu(2) %>
          <nav class="secondary">
                <% with $Level(1) %>
             <h3>
                   $Title
             </h3>
             <ul>
                   <% include SidebarMenu %>
             </ul>
                <% end_with %>
          </nav>
       <% end_if %>

    </aside>

  • Thomashv
    Avatar
    Community Member
    32 Posts

    Re: SS 3.0.3 - Loop children not limited to children of current page - SOVLED Link to this post

    And then a half year almost was gone... But thank you very much for the clearification.

    2195 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.