Skip to content

Instantly share code, notes, and snippets.

@kevsimpson
Created July 18, 2014 10:12
Show Gist options
  • Save kevsimpson/8ae5b9b469fa4e049496 to your computer and use it in GitHub Desktop.
Save kevsimpson/8ae5b9b469fa4e049496 to your computer and use it in GitHub Desktop.
umbraco: subnav
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var homePage = CurrentPage.AncestorsOrSelf(2).First();
}
@* Render the sitemap by passing the root node to the traverse helper *@
<nav class="nav nav--sub">
@* <a href="@homePage.Url" class="@(CurrentPage.Id == homePage.Id ? "active" : null) nav__link">@homePage.Name</a> *@
@Traverse(homePage)
</nav>
@* Helper method to travers through all descendants *@
@helper Traverse(dynamic node) {
@* Update the level to reflect how deep you want the sitemap to go *@
var maxLevelForSitemap = 6;
@* Select visible children *@
var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap).Where("NodeTypeAlias != @0", "Article").Where("NodeTypeAlias != @0", "Vacancy").Where("NodeTypeAlias != @0", "LinkEntry");
@* If any items are returned, render a list *@
if (items.Any()) {
<ul>
@foreach (var item in items) {
<li class="[email protected]">
<a href="@item.Url" class="@(CurrentPage.Id == item.Id ? "active" : null) nav__link">@item.Name</a>
@* Run the traverse helper again *@
@Traverse(item)
</li>
}
</ul>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment