As you can see in the screenshot, this works fine if you are on the 'Members' page:
However, when you select a single member, the navigation disappears:
So I wonder if it is possible to adjust the Razor script, so that it doesn't traverse on Children of the 'Members Area' node, but renders all nodes of the document type 'member' so that the navigation menu also shows the other members when a sinlge member is selected in the navigation.
how to get nodes by Document Type in Razor
Hi,
For a navigation menu I need to show all nodes of a certain document type ('member')
The current Razor script I have render the navigation menu by showing all the child nodes of the parent 'members area' node:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
List<string> categories = new List<string> {"Professor", "Researcher", "Teaching Assistant", "Practitioning Assistant", "Affiliate Member"};
DynamicNodeList categorieItems = new DynamicNodeList();
foreach (var category in categories)
{
categorieItems = @Model.Children.Where("memberCategory == \"" + category + "\"");
if (categorieItems.Items.Any())
{
<h3>@category</h3>
<ul class="nav">
@foreach(DynamicNode item in categorieItems)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}
}
}
As you can see in the screenshot, this works fine if you are on the 'Members' page:
However, when you select a single member, the navigation disappears:
So I wonder if it is possible to adjust the Razor script, so that it doesn't traverse on Children of the 'Members Area' node, but renders all nodes of the document type 'member' so that the navigation menu also shows the other members when a sinlge member is selected in the navigation.
Thanks for your help,
Anthony
Hi Anthony.
You can use AncestorOrSelf("Document type alias") to get the closest parent or self from this type and then get the children.
In your example :
categorieItems = @Model.AncestorOrSelf("members Folder Document Type Alias").Children.Where("memberCategory == \"" + category + "\"");
Or you can get the parent before the loop like this :
DynamicNode parent = @Model.AncestorOrSelf("members Folder Document Type Alias");
and then inside the foreach :
categorieItems = parent.Children.Where("memberCategory == \"" + category + "\"");
Cheers.
Hi gilad,
Again you come to the rescue, thanks. I used the first method:
categorieItems = @Model.AncestorOrSelf("members Folder Document Type Alias").Children.Where("memberCategory == \"" + category + "\"");
And this works fine
Greetings,
Anthony
is working on a reply...