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.

Archive /

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

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

Quick question about showing different navigation levels (solved I think)


Go to End


6 Posts   10059 Views

Avatar
SilverRay

Community Member, 167 Posts

9 December 2007 at 9:14pm

Edited: 10/01/2008 10:48pm

Just a quick question about enabling navigation levels with SS. I understand the control structures as depicted in the first tutorial. I can make pages that show the second level of navigation (or whatever level, being handled by <% control Menu(2) %>). But if I want to show the second navigation level at all times, but with each second level navigation menu belonging to its main navigational parent? An example of this would be css drop-down menus as described in articles like <http://www.alistapart.com/articles/horizdropdowns/>;... How would I do that with SS? Can it be done with the standard menu page controls? If so, I don't see how, but perhaps anybody else does?

Many thanks for your reply!

(edited because of probable solution)

Avatar
Fuzz10

Community Member, 791 Posts

9 December 2007 at 11:19pm

There's probably an easier way.

But if there are just 2 or 3 levels max I'd just do something like this ..

Sorry 'bout the pseudo code.. :

// Get all top level menu-tems)
DataObject::get("SiteTree", "ShowInSearch = 1 AND ParentID=0");

// Loop through them
foreach (toplevel-menu-item) {

// get all children for this menu-item
DataObject::get("SiteTree", "ShowInSearch = 1 AND ParentID= current-menu-itemID");

// Loop through the children as well
foreach (2ndlevel-menu-item) {

// do - stuff
}

}

Good luck !

Avatar
SilverRay

Community Member, 167 Posts

9 December 2007 at 11:27pm

Thanks Fuzz10!

I figured it needed some custom coding... I will try something like this (although I'm not sure my current coding skills allow for that, but hey, I should start somewhere ;)

Thanks!

Avatar
SilverRay

Community Member, 167 Posts

10 January 2008 at 10:46pm

Maybe I solved my little problem (and slapping my forehead for not seeing this) and is this the easier way indeed (example of simplified code):

<ul id="mainnav">
<% control Menu(1) %>
<li><a href="$Link">$MenuTitle</a>

<ul id="subnav">
<% control Children %>
<li><a href="$Link">$MenuTitle</a></li>
<% end_control %>
</ul>

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

This works and it doesn't break, no forbidden nested page controls either... or do I miss something?

Avatar
linuxlover101

Community Member, 2 Posts

26 January 2008 at 1:50pm

I've been trying to figure out the same thing. I tried your code that you came up with and all I get is empty sub-menus.

<div id="menu">
<ul id="nav-one" class="nav">

<li class="current"><a href="/silverstripe/home/" title="Go to the &quot;Home&quot; page">Home</a>
<ul class="sfHeader"></ul>
</li>

<li class="link"><a href="/silverstripe/about-us/" title="Go to the &quot;About Us&quot; page">About Us</a>
<ul class="sfHeader"></ul>
</li>

<li class="link"><a href="/silverstripe/contact-us/" title="Go to the &quot;Contact Us&quot; page">Contact Us</a>

<ul class="sfHeader"></ul>
</li>

</ul>
</div>

This is the template code I use.

<div id="menu">
<ul id="nav-one" class="nav">
<% control Menu(1) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a>
<ul class="sfHeader">
<% control Menu(2) %>
<li><a href="$Link">$MenuTitle</a></li>
<% end_control %>
</ul></li>
<% end_control %>
</ul>
</div>

Avatar
linuxlover101

Community Member, 2 Posts

26 January 2008 at 2:12pm

Never mind on my inquiry. I changed
<% control Menu(2) %> to <% control Children %> and everything's good. :D