Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Vert Nav 2nd level issue.

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 3643 Views
  • dancrew32
    Avatar
    Community Member
    15 Posts

    Vert Nav 2nd level issue. Link to this post

    So I'm trying to setup a multi-level vertical nav that only displays the children of the page that it's on.

    The issue: with the code below, if you navigate to one of the second level pages, all the children in the vertical nav will go away. I want all of the 2nd level links to continue being displayed when you're on 2nd level pages.

    In my navigation.ss file:

    <ul>
       <% control Menu(1) %>
          <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a>
             <% if isSection %>
                <% control Children %>
                   <ul class="lvl2">
                      <li class="lvl2"><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levela"><span><em>$MenuTitle</em></span></a></li>
                   </ul>
                <% end_control %>
             <% end_if %>
          </li>
       <% end_control %>
    </ul>   

    Any ideas would be greatly appreciated. =]

  • contigo
    Avatar
    Community Member
    16 Posts

    Re: Vert Nav 2nd level issue. Link to this post

    I've been playing with submenus too. Try replacing

    <% if isSection %>

    with

    <% if LinkOrSection = section %>

    -billy

  • dancrew32
    Avatar
    Community Member
    15 Posts

    Re: Vert Nav 2nd level issue. Link to this post

    As that works, I think the problem with my code is that when you navigate to the 2nd level page, it's looking for <% control Children %> so it starts looking for 3rd level children (which don't exist, so it displays nothing). What might be a work-around for this?

  • contigo
    Avatar
    Community Member
    16 Posts

    Re: Vert Nav 2nd level issue. Link to this post

    maybe this...

                 <% if LinkOrSection = section %>
                    <% if Children %>

  • dancrew32
    Avatar
    Community Member
    15 Posts

    Re: Vert Nav 2nd level issue. Link to this post

    see I think by saying if Children it's still looking for 3rd level children when you're on a 2nd level page.. kinda frustrating lol..

  • contigo
    Avatar
    Community Member
    16 Posts

    Re: Vert Nav 2nd level issue. Link to this post

    "see I think by saying if Children it's still looking for 3rd level children when you're on a 2nd level page.. kinda frustrating lol."

    Not sure if I'm understanding correctly. Calling Children is context-sensitive and should only grab 3rd level children if they exist. Some code that should always show all submenus...

    <% control Menu(1) %>
    add level one menu stuff here
    <% control Children %>
    add level two menu stuff here
    <% control Children %>
    add level three menu stuff here
    <% end_control %>
    <% end_control %>
    <% end_control %>

    Another example - always shows parents, only shows children of the page you are on...

    <% if Menu(1) %>
       <ul class="firstLevel">
          <% control Menu(1) %>
                <li><a href="$Link" title="$MenuTitle" class="$LinkingMode">$MenuTitle</a>
       
                   <% if LinkOrSection = section %>
                      <ul class="secondLevel">            
                         <% control Children %>
                            <li class="$LinkingMode <% if FirstLast %>$FirstLast<% end_if %>">
                               <a href="$Link" title="$MenuTitle" class="$LinkingMode">$MenuTitle</a>
                               <% if LinkOrSection = section %>
                                     <ul class="thirdLevel">
                                        <% control Children %>
                                           <li class="$LinkingMode <% if FirstLast %> $FirstLast<% end_if %>">
                                              <a href="$Link" title="$MenuTitle" class="$LinkingMode">$MenuTitle</a>
                                           </li>
                                        <% end_control %>
                                     </ul>
       
                               <% end_if %>
             
                            </li>
                         <% end_control %>
                      </ul>
                   <% end_if %>
       
                </li>
          <% end_control %>
       </ul>
    <% end_if %>

  • contigo
    Avatar
    Community Member
    16 Posts

    Re: Vert Nav 2nd level issue. Link to this post

    The 2nd example doesn't need <% if children %> because that's part of what <% control Children %> does. Well, at least that's my understanding of it all. Let me know if I'm not understanding/helping

    -Billy

  • dancrew32
    Avatar
    Community Member
    15 Posts

    Re: Vert Nav 2nd level issue. Link to this post

    you rock, kind sir. that 2nd one is the ticket. thanks so very much

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