Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Section Navigation

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

Page: 1
Go to End
Author Topic: 1539 Views
  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Section Navigation Link to this post

    Hello,

    My site structure is something similar to this

    Section 1

    Section 2
    - Sub 1
    - Sub 2
    -Sub Sub
    -Sub 3

    Section 3
    - Sub 1

    What I am trying to do, is create a secondary navigation that only appears if the section has children, and if so, displays the section name at the top, and then shows the list of pages below. No matter which page within that section you are viewing it should appear the same.

    Can anyone tell me how to achieve that?

  • Trym
    Avatar
    Community Member
    18 Posts

    Re: Section Navigation Link to this post

    Hi Dan

    If you post your *.ss file it may be easier to help.

    You may look at http://doc.silverstripe.com/doku.php?id=built-in-page-controls
    and use something like:
    <% if Children %>
       <% control Children %>
          $MenuTitle
       <% end_control %>
    <% end_if %>

    An example can also be found in http://doc.silverstripe.com/doku.php?id=html under the header Menus.

    Best regards Trym

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: Section Navigation Link to this post

    Right now, this is the code I am using to generate the sub nav.

    <% control Level(1) %>
          <div id="subNav">
             <h4>$Title.XML</h4>
             <ul>
             <% control Children %>
                <li><a href="$Link" class="$LinkingMode secondLevel" title="$Title.XML">$MenuTitle</a>
                <% control Children %>
                <li class="$LinkingMode thirdLevel">+ <a href="$Link" class="$LinkingMode" title="$Title.XML"><span>$MenuTitle</span></a>
                <% end_control %>
             <% end_control %>
             </ul>
          </div>
       <% end_control %>

    Now, how can I only make everything here show up if the current section has sub pages? If it does not have sub pages, then this shouldn't show on the page.

  • Trym
    Avatar
    Community Member
    18 Posts

    Re: Section Navigation Link to this post

    Hi Dan,

    Try to embed your menu (<% control Level(1) %> ..<% end_control %>) in <% if Children %>.. <% end_if %>

    Best regards Trym

  • DanStephenson
    Avatar
    Community Member
    115 Posts

    Re: Section Navigation Link to this post

    Thanks Trym. In case anyone else has a similar issue, here is what seems to be working for me:

       <% control Level(1) %>
       <% if Children %>
          <div id="subNav">
             <h4>$Title.XML</h4>
             <ul>
             <% control Children %>
                <li><a href="$Link" class="$LinkingMode secondLevel" title="$Title.XML">$MenuTitle</a>
                <% control Children %>
                <li class="$LinkingMode thirdLevel">+ <a href="$Link" class="$LinkingMode" title="$Title.XML"><span>$MenuTitle</span></a>
                <% end_control %>
             <% end_control %>
             </ul>
          </div>
       <% end_if %>
       <% end_control %>

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