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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Section Navigation


Go to End


5 Posts   2806 Views

Avatar
DanStephenson

Community Member, 116 Posts

6 February 2009 at 10:24am

Edited: 06/02/2009 10:25am

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?

Avatar
Trym

Community Member, 18 Posts

7 February 2009 at 1:02am

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

Avatar
DanStephenson

Community Member, 116 Posts

7 February 2009 at 7:34am

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.

Avatar
Trym

Community Member, 18 Posts

12 February 2009 at 1:45am

Hi Dan,

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

Best regards Trym

Avatar
DanStephenson

Community Member, 116 Posts

13 February 2009 at 10:53am

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