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.

Template Questions

Menu Troubles – Children of Children.


Reply

4 Posts   2071 Views

Avatar
stew

14 November 2009 at 4:11am Community Member, 30 Posts

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

Avatar
madmaurice

30 November 2009 at 1:07am (Last edited: 30 November 2009 1:10am), Community Member, 20 Posts

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

Avatar
thepurpleblob

7 December 2009 at 2:25am Community Member, 28 Posts

<% if LinkOrSection = section %>

should be

<% if LinkOrSection == section %>

surely?

Avatar
Pigeon

7 December 2009 at 11:40am Community Member, 243 Posts

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