Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello Umbracians!
I have trying to create a navigation with submenus (drop downs) based of the the node tree.
This is the code I have been using for the basic navigation:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ @*Get the root of the website *@ var homeNode = CurrentPage.AncestorOrSelf(1); } <ul id="main-menu"> <li class="@(homeNode.Name == CurrentPage.Name ? "current-selected" : null)"> <a href="@homeNode.Url">@(homeNode.alternativeName == "" ? homeNode.Name : homeNode.alternativeName)</a> </li> @foreach (var page in homeNode.Children.Where("Visible")) { <li class="@(page.IsAncestorOrSelf(CurrentPage) ? "current-selected" : null)"> <a href="@page.Url">@(page.alternativeName == "" ? page.Name : page.alternativeName)</a> </li> } </ul>
but now I need check each node for the existence on children and then loop through them.
Any assistance would be great.
Phillip
Hi Phillip,
Could you not introduce another for each loop inside your existing one?
@{ var homeNode = CurrentPage.AncestorOrSelf(1); foreach (var page in homeNode.Children.Where("Visible")) { <li> <a href="@page.Url">page.Name</a> @if (page.Children.Where("Visible").Any()) { <ul> @foreach (var child in page.Children.Where("Visible")) { <li><a href="@child.Url">@child.Name</a></li> } </ul> } </li> } }
Hope this helps.
Thanks, Dan.
Worked indeed.
Many thanks!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Navigation with drop downs
Hello Umbracians!
I have trying to create a navigation with submenus (drop downs) based of the the node tree.
This is the code I have been using for the basic navigation:
but now I need check each node for the existence on children and then loop through them.
Any assistance would be great.
Phillip
Hi Phillip,
Could you not introduce another for each loop inside your existing one?
Hope this helps.
Thanks, Dan.
Worked indeed.
Many thanks!
Phillip
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.