Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Quick question about showing different navigation levels (solved I think)

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: 9188 Views
  • SilverRay
    Avatar
    Community Member
    167 Posts

    Quick question about showing different navigation levels (solved I think) Link to this post

    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)

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Quick question about showing different navigation levels (solved I think) Link to this post

    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 !

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Quick question about showing different navigation levels (solved I think) Link to this post

    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!

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Quick question about showing different navigation levels (solved I think) Link to this post

    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?

  • linuxlover101
    Avatar
    Community Member
    2 Posts

    Re: Quick question about showing different navigation levels (solved I think) Link to this post

    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>

  • linuxlover101
    Avatar
    Community Member
    2 Posts

    Re: Quick question about showing different navigation levels (solved I think) Link to this post

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

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