I have a problem with my multi-level menu in Umbraco 7.3 - it works for level 1& 2 and I found a solution for level 3 but don't know how to reference/call the level 3 pages.
here is my code:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
Macro to display child pages below the root page of a standard website.
Also highlights the current active page/section in the navigation with
the css class "current".
*@
@{
var root = CurrentPage.AncestorOrSelf(1);
}
<div id="navigation" class="navbar navbar" role="navigation">
<div class="container">
<ul class="nav navbar-nav">
@foreach (var page in Model.Content.AncestorOrSelf(1).Children.Where("Visible"))
{
<li>
@{
if (page.Children.Where("Visible").Count() > 0)
{
<li class="dropdown">
<a class="dropdown-toggle"href="@page.Url">@page.Name</a>
<ul class="dropdown-menu" role="menu">
@foreach (var subpage in page.Children.Where("Visible"))
{
<li>
<a href="@subpage.Url">@subpage.Name</a></li>
foreach (var childPage in subpage.Children.Where("Visible"))
{
<ul>
<li>
<a href="@subpage.Url">@subpage.Name</a>
</li>
</ul>
}
}
</ul>
</li>
}else
{
<a href="@page.Url">@page.Name</a>
}
}
</li>
}
</ul>
</div>
</div><!--navigation-->
At the moment it lists the last subpage 4 times as level 3. What do I call the subpage of a subpage? or do I have to do it another way. Any help appreciated I'm pulling my hair out.
? I could obviously hardcode the classes into something like the above, but I want the grandparent, parent and child classes to be dynamic. So if you're on a level 2 page you'll see a parent and child class on the pages on levels 1 & 3, but if you're on a level 3 page you'd see parent and grandparent classes.
Any ideas on how to do that?
Edit: Not to worry, I've decided this isn't required.
Multi level menu - 3rd level
Help
I have a problem with my multi-level menu in Umbraco 7.3 - it works for level 1& 2 and I found a solution for level 3 but don't know how to reference/call the level 3 pages.
here is my code:
At the moment it lists the last subpage 4 times as level 3. What do I call the subpage of a subpage? or do I have to do it another way. Any help appreciated I'm pulling my hair out.
Thanks Natasha
Hi Natasha,
Please change nested foreach like that:
Thanks,
Oleksandr
Thank you so much Alex
Is it posible to activate the nested for each only when the upper level is active?
I'am new to razor and want to use it as Subnavigation. I also saw solutions with helpers.
Hi Bas,
Do you want to activate child item when parent is active ?
That's exactly what I mean.
Not quite sure if this is what you mean, but try it.
Thanks for your answer. Almost there :-).
When I enter a subpage the selected subpage disappears. I think i need something like "if currentpage and parentpage are selected".
I also described this in: https://our.umbraco.org/forum/developers/razor/71192-help-with-left-navigation
Just searching for the best solution.
In the above example how would I add in dynamic classes on the various menu levels so the resulting html would look like so:
? I could obviously hardcode the classes into something like the above, but I want the grandparent, parent and child classes to be dynamic. So if you're on a level 2 page you'll see a parent and child class on the pages on levels 1 & 3, but if you're on a level 3 page you'd see parent and grandparent classes.
Any ideas on how to do that?
Edit: Not to worry, I've decided this isn't required.
is working on a reply...