Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Created February 1, 2012 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save warrenbuckley/1718099 to your computer and use it in GitHub Desktop.
Save warrenbuckley/1718099 to your computer and use it in GitHub Desktop.
Umbraco V5 Example - Sitemap HTML
@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