Created
March 2, 2012 13:12
-
-
Save warrenbuckley/1958307 to your computer and use it in GitHub Desktop.
ListAllDescendatsFromCurrentPage
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 | |
@* 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