Jump to:

22976 Posts in 11667 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » **SOLVED** Children of Children?

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

Page: 1 2
Go to End
Author Topic: 567 Views
  • ambient
    Avatar
    Community Member
    113 Posts

    **SOLVED** Children of Children? Link to this post

    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>

  • Devlin
    Avatar
    Community Member
    186 Posts

    Re: **SOLVED** Children of Children? Link to this post

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

  • ambient
    Avatar
    Community Member
    113 Posts

    Re: **SOLVED** Children of Children? Link to this post

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

  • ambient
    Avatar
    Community Member
    113 Posts

    Re: **SOLVED** Children of Children? Link to this post

    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?

  • Devlin
    Avatar
    Community Member
    186 Posts

    Re: **SOLVED** Children of Children? Link to this post

    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.

  • ambient
    Avatar
    Community Member
    113 Posts

    Re: **SOLVED** Children of Children? Link to this post

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

  • IOTI
    Avatar
    Community Member
    187 Posts

    Re: **SOLVED** Children of Children? Link to this post

    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.

  • Devlin
    Avatar
    Community Member
    186 Posts

    Re: **SOLVED** Children of Children? Link to this post

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

    567 Views
Page: 1 2
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.