Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Created March 2, 2012 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save warrenbuckley/1958307 to your computer and use it in GitHub Desktop.
Save warrenbuckley/1958307 to your computer and use it in GitHub Desktop.
ListAllDescendatsFromCurrentPage
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
@if (DynamicModel.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = DynamicModel.Children.Where("umbracoNaviHide != @0", "True").First().Level;
@* Add in level for a CSS hook *@
<ul class="level-@naviLevel">
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in DynamicModel.Children.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>
@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children)
}
</li>
}
</ul>
}
@helper childPages(dynamic pages)
{
@* Ensure that we have a collection of pages *@
if (pages.Any())
{
@* Get the first page in pages and get the level *@
var naviLevel = pages.First().Level;
@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@foreach (var page in pages.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@page.Url">@page.Name</a>
@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (page.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment