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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

**SOLVED** Children of Children?


Go to End
Reply


9 Posts   842 Views

Avatar
ambient

Community Member, 123 Posts

13 February 2013 at 3:56am

Edited: 13/02/2013 5:23am

Hi All,
I've been beating my head against the wall with this one.
I have a Sidebar menu which displays the page (Services) and then the children of the page (Service1, Service2 etc.)

What I want is to also be able to show the Children of the subpages as well. Something Like this:

Services
    Service1
      Service1 Extra Details
      Service1 Extra Info
      Service1 Extra Other
   Service2
      Service2 Extra Details
      Service2 Extra Info
   Service3
      Service3 Extra Details

Is this possible?

All I have so far is this

<ul id="Menu2">
          <% control Menu(2) %>
          <% if Children %>
              <li class="$LinkingMode"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela"><span>$MenuTitle.XML</span></a>

            <% end_if %>   
          
             <% if LinkOrSection = section %>
                <% if Children %>
                  <ul class="sub">
                     <li>
                        <ul class="roundWhite">
                           
                           <% control Children %>
                              <li><a style="padding-left:40px; font-size:10px" href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levelb"><span>$MenuTitle.XML</span></a></li>
<% end_control %>

                        </ul>
                     </li>
                  </ul>
                 <% end_if %>
            <% end_if %>
         </li>
         <% end_control %>
      </ul>

Avatar
Devlin

Community Member, 225 Posts

13 February 2013 at 6:06am

As you already mentioned, it is in fact children of children.

<% if Children %>
<ul>
   <% control Children %>
   <li>
      <a href="$Link" class="$LinkingMode levelb"><span>$MenuTitle.XML</span></a>
      <% if Children %>
      <ul>
         <% control Children %>
         <li>
            <a href="$Link" class="$LinkingMode levelc"><span>$MenuTitle.XML</span></a>
         </li>
         <% end_control %>
      </ul>
      <% end_if %>
   </li>
   <% end_control %>
</ul>
<% end_if %>

Avatar
ambient

Community Member, 123 Posts

14 February 2013 at 12:11am

Thank you so much Devlin, I tried so many variations but never got his one!
Brilliant :)

Avatar
ambient

Community Member, 123 Posts

14 February 2013 at 12:40am

Actually it's not quite solved yet, D'oh!

When I go to any of the subpages I'd still like to have the full menu for that section show (parent pages included).
Instead it's only showing children of the current page?
Any ideas on this?

Avatar
Devlin

Community Member, 225 Posts

14 February 2013 at 12:55am

This is because of the "<% if LinkOrSection = section %>" and the corresponding "<% end_if %>" in your template. It checks if the page is currently active or is a parent page of your current page... and if this is the case, the template will show the submenu.
If you remove this, the template will always show the submenu.

Avatar
ambient

Community Member, 123 Posts

14 February 2013 at 1:01am

Hi Devlin,

"<% if LinkOrSection = section %>" doesn't seem to be in my code. This is what I have right now:

<% if Children %>
<ul id="nav2" class="mobnav nav">
<% control Children %>
<li class="$LinkingMode"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela"><span>$MenuTitle.XML</span></a>
<% if Children %>
<ul>
   
<% control Children %>
<li>
<li><a style="padding-left:40px; font-size:10px" href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levelb"><span>$MenuTitle.XML</span></a></li>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
<% end_if %>

Avatar
copernican

Community Member, 189 Posts

14 February 2013 at 2:16am

Hi Ambient

This is probably a CSS issue now. If you inspect your html you'll see that $LinkingMode returns either current, or section depending on the page current being viewed. You'll have to properly setup your CSS to work with these class names to display your menu how you want it.

Avatar
Devlin

Community Member, 225 Posts

14 February 2013 at 2:26am

You still need the control Menu(2) in your template to deliver the template a starting point for seeking children. Right now the template checks if the current page has children.

<% if Menu(2) %>
<ul>
   <% control Menu(2) %>
   <li>
      <a href="$Link" class="$LinkingMode levela"><span>$MenuTitle.XML</span></a>
      <% if Children %>
      <ul>
       <% control Children %>
       <li>
          <a href="$Link" class="$LinkingMode levelb"><span>$MenuTitle.XML</span></a>
          <% if Children %>
          <ul>
             <% control Children %>
             <li>
               <a href="$Link" class="$LinkingMode levelc"><span>$MenuTitle.XML</span></a>
             </li>
             <% end_control %>
          </ul>
          <% end_if %>
       </li>
       <% end_control %>
      </ul>
      <% end_if %>
   </li>
   <% end_control %>
<% end_if %>

Go to Top