You could just create yet another foreach loop with subpage, e.g. subsubpage, but it might make sense to use a Razor Helper method instead. e.g. something based on this:
@inherits UmbracoTemplatePage
<nav id="nav" class="skel-panels-fixed">
<ul>
@{
var maxLevelForNav = 4;
var home = CurrentPage.AncestorOrSelf(1);
@RenderNavForNode(home, 1)
foreach (var page in home.Children.Where("Visible"))
{
@RenderNavForNode(page, maxLevelForNav);
}
}
</ul>
</nav>
@helper RenderNavForNode(dynamic page, int maxLevel)
{
var current = CurrentPage.Id == page.Id ? "active" : null;
<li><a class="@current" href="@page.Url">@page.Name</a></li>
if (page.Children.Where("Visible").Any() && page.Level < maxLevel)
{
<ul>
@foreach (var subPage in page.Children.Where("Visible"))
{
@RenderNavForNode(subPage, maxLevel)
}
</ul>
}
}
3 level navigation
Hi there,
I'm new to Umbraco - and Razor. I'm having trouble creating a 3rd level dropdown nav. My Navigation partial looks like this...
I'm just not sure how to pull out the third level links - and if in fact I'm going about this the best way?
Any help would be massively appreciated :-)
I'm using Umbraco 7.
Hi Dan and welcome to Our!
You could just create yet another foreach loop with subpage, e.g. subsubpage, but it might make sense to use a Razor Helper method instead. e.g. something based on this:
Jeavon
edited above to add maxLevel constraint
Hey Jeavon,
Thanks so much for the response!
How would I go about adding another foreach loop? What I've tried below doesn't quite work
<div class="col-md-4">
@foreach (var subpage in page.Children.Where("Visible")){
<h4 class="list-title">@subpage.Name</h4>
foreach( var childPage in page.Children.Where("Visible")){
<!-- Links Here -->
}
}
</div>
I think only that the second one needs to look at Children of subpage:
is working on a reply...