List Child Pages from Changeable Source

  • Download Gist
ListChildPagesFromChangeableSource.cshtml
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
 
@{
@* Get the macro parameter and check it has a value otherwise set to empty hive Id *@
var startNodeID = String.IsNullOrEmpty(Model.MacroParameters.startNodeID) ? HiveId.Empty.ToString() : Model.MacroParameters.startNodeID;
}
 
@* Check that startNodeID is not an empty HiveID AND also check the string is a valid HiveID *@
@if (startNodeID != HiveId.Empty.ToString() && HiveId.TryParse(startNodeID).Success)
{
@* Get the start node as a dynamic node *@
var startNode = Umbraco.GetDynamicContentById(startNodeID);
@* Check that startNode has children pages, where the property umbracoNaviHide is not True *@
if (startNode.Children.Where("umbracoNaviHide != @0", "True").Any())
{
<ul>
@* For each child page under startNode, where the property umbracoNaviHide is not True *@
@foreach (var page in startNode.Children.Where("umbracoNaviHide != @0", "True"))
{
<li><a href="@page.Url">@page.Name</a></li>
}
</ul>
}
}

What is the proper way to do a query like .Where("umbracoNaviHide != @0", "True") in 5.1+?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.