Created
February 1, 2012 17:14
-
-
Save warrenbuckley/1718099 to your computer and use it in GitHub Desktop.
Umbraco V5 Example - Sitemap HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits PartialViewMacroPage | |
@using Umbraco.Cms.Web | |
@using Umbraco.Cms.Web.Macros | |
@using Umbraco.Framework | |
@{ | |
//Get the current page | |
var currentPage = DynamicModel; | |
//Will walk up the tree to the last ancestor node aka RootNode | |
var rootNode = currentPage.AncestorsOrSelf.Last(); | |
<nav id="sitemap"> | |
<ul class="level-@(rootNode.Level)"> | |
<li> | |
<a href="@rootNode.Url">@rootNode.Name</a> | |
@* Display children on rootNode *@ | |
@childPages(rootNode.Children) | |
</li> | |
</ul> | |
</nav> | |
} | |
@helper childPages(dynamic pages) | |
{ | |
//Check we have pages to loop through | |
if (pages.Any()) | |
{ | |
//Get the navigation level | |
var naviLevel = pages.First().Level; | |
<ul class="level-@(naviLevel)"> | |
@foreach (var page in pages) | |
{ | |
//Check the page is not hidden with umbracoNaviHide | |
if (page.umbracoNaviHide != "True") | |
{ | |
<li> | |
<a href="@page.Url">@page.Name</a> | |
@* if the current page has any children *@ | |
@if (page.Children.Any()) | |
{ | |
@childPages(page.Children); | |
} | |
</li> | |
} | |
} | |
</ul> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment