Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hefin Jones 39 posts 161 karma points
    Jul 08, 2013 @ 14:16
    Hefin Jones
    0

    Simple Sub Navigation Script

    Good Afternoon,

    I'm trying to put together a simple sub-navigation menu, that will display

    1. If you are on the parent page: will show a list of children for that section
    2. If you are on a child page: will show a list of the other children for that section
    The structure of the site in this case would be similar to this:
    Home 
    -- About the project (sub nav to display list of children
      ---- Towards Zero Waste (sub nav to display all children of this section as parent does)
      ---- Reducing Landfill (sub nav to display all children of this section as parent does)
      ---- Join Committee (sub nav to display all children of this section as parent does)
    I can get this to work on the parent page, but obviously when I enter the sub page the navigation disappears.  This is what I've got so far:

    <nav>
    <ul id="subNavigation">
    @if(Model.Children.Where("Template != 0").Where("Visible").Count() > 0) {
    foreach(var page in Model.Children.Where("Template != 0").Where("Visible")) {
    var selected = page.Id == Model.Id ? " selected" : "";
    <li class="[email protected](selected)"><a href="@page.Url">@page.Name</a></li>
    }
    }
    </ul>
    </nav>
    How to I taylor this script for the sub pages as well as parent page?
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 08, 2013 @ 14:55
    Fuji Kusaka
    0

    Hi Hefin,

    You could try do something like

    var parent = Model.AncestorOrSelf(3); // 3 is the Level from the Content Section that is  -- Towards Zero , -- Reducing Landfill etc

     @if(parent !=null){
         foreach(var page in parent.Children.Where("umbracoNaviHide != true")){
                 var selected = page.IsAncestorOrSelf(Model)? "class=selected": "";
           <li @selected><a href="@page.Url">@page.Name</a></li>
    }
    }

    Hope it helps

     

     

Please Sign in or register to post replies

Write your reply to:

Draft