Files
Umbraco-CMS/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListDescendantsFromCurrentPage.cshtml
2018-11-22 14:05:51 +00:00

69 lines
2.3 KiB
Plaintext
Executable File

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Umbraco.Core.Models
@using Umbraco.Web
@*
This snippet creates links for every single page (no matter how deep) below
the page currently being viewed by the website visitor, displayed as nested unordered HTML lists.
*@
@{ var selection = Model.Content.Children.Where(x => x.IsVisible()).ToArray(); }
@* Ensure that the Current Page has children *@
@if (selection.Length > 0)
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = selection[0].Level;
@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@* Loop through the selection *@
@foreach (var item in selection)
{
<li>
<a href="@item.Url">@item.Name</a>
@* if this child page has any children, where the property umbracoNaviHide is not True *@
@{
var children = item.Children.Where(x => x.IsVisible()).ToArray();
if (children.Length > 0)
{
@* Call our helper to display the children *@
@ChildPages(children)
}
}
</li>
}
</ul>
}
@helper ChildPages(IPublishedContent[] selection)
{
@* Ensure that we have a collection of pages *@
if (selection.Length > 0)
{
@* Get the first page in pages and get the level *@
var naviLevel = selection[0].Level;
@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@foreach (var item in selection)
{
<li>
<a href="@item.Url">@item.Name</a>
@* if the page has any children, where the property umbracoNaviHide is not True *@
@{
var children = item.Children.Where(x => x.IsVisible()).ToArray();
if (children.Length > 0)
{
@* Recurse and call our helper to display the children *@
@ChildPages(children)
}
}
</li>
}
</ul>
}
}