Jump to:

3397 Posts in 978 Topics by 854 members

Template Questions

SilverStripe Forums » Template Questions » Menu Troubles – Children of Children.

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

Page: 1
Go to End
Author Topic: 2016 Views
  • stew
    Avatar
    Community Member
    30 Posts

    Menu Troubles – Children of Children. Link to this post

    Hey guys,

    I've managed to get the vast majority of the site I've been working on up and running, however I've run into a bit of a snag with getting Children of Children working...

    My site tree looks like this:

    The pages under Championships > WTCC – Race Pro > Results do not show up in the menu (it's the pages Round 5 Qualifying etc.)

    My code for the sidebar is as follows:

    <div id="Sidebar" class="typography">
       <div class="sidebarBox">
          <h3>
             <% control Level(1) %>
                $Title
             <% end_control %>
          </h3>
          <ul id="Menu2">
              <% control Menu(2) %>

                <% if Children %>
                   <li class="$LinkingMode"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela">$MenuTitle.XML</a></li>
                <% else %>
                   <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela">$MenuTitle.XML</a></li>
                <% end_if %>   

                <% if LinkOrSection = section %>

                   <% if Children %>
                   <li>
                      <ul class="sub">
                            <li><a href="$CalendarLink" class="levelb">Calendar</a></li>
                         <% control Children %>
                            <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levelb">$MenuTitle.XML</a></li>
                         <% end_control %>
                      </ul>
                   </li>
                   <% end_if %>

                <% end_if %>

             <% end_control %>
          </ul>
          <div class="clear">&nbsp;</div>
       </div>
       <div class="sidebarBox">
          <h3>Search</h3>
       $SearchForm
       </div>
    </div>

    I've tried duplicating the Menu(2) control and replacing the 2 with a 3 but that didn't work...

    Am I mad to try and do children of children or is there a way around it?

    Thanks,

    Stewart

  • madmaurice
    Avatar
    Community Member
    20 Posts

    Re: Menu Troubles – Children of Children. Link to this post

    maybe its because you only use control Children once?

    so the menu only reaches the third level. but the page you want to see is on the fourth

    sry if i am wrong or misunderstood your problem. im a totally noob at silverstripe^^

  • thepurpleblob
    Avatar
    Community Member
    28 Posts

    Re: Menu Troubles – Children of Children. Link to this post

    <% if LinkOrSection = section %>

    should be

    <% if LinkOrSection == section %>

    surely?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Menu Troubles – Children of Children. Link to this post

    I've never had to implement large nested menus before, but that doesn't mean i haven't thought about how to solve the problem of having a navigation that can have a large number of nested items.

    My thoughts have always been to put the children control within an include so that it can iterate.

    This file would be Navigation.ss in Includes

    <% if Children %>
    <ul>
    <% control Children %>
    <li class="$LinkingMode"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela">$MenuTitle.XML</a>
    <% include Navigation.ss %>
    </li>
    <% end_control %>
    </ul>
    <% end_if %>

    This is obviously a gross simplification, but it basically would mean that every page gets checked for a child, and if it has a child, it then includes a nested list of the child pages. It works in a similar way to the site map [http://doc.silverstripe.org/doku.php?id=tutorial:site-map#step_1creating_the_page_type] (in terms of looping).

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