However, I want to add some dropdowns to the menus for nodes with children using the following html code;
<div data-hover="1" data-delay="0" class="w-dropdown">
<div class="navlink w-dropdown-toggle">
<div>What we do</div>
</div>
<nav class="w-dropdown-list"><a href="#" class="navlink w-dropdown-link">Drop Down link 1</a><a href="#" class="navlink w-dropdown-link">rop Down link 2</a><a href="#" class="navlink w-dropdown-link">rop Down link 3</a></nav>
</div>
Would anyone be able to help how I can add this to my code?
Just to add on to the reply of Kieron, keep in mind that the suggested code contains a common pitfall (over-querying). A solution that solves this issue would be something like:
@foreach (var item in selection)
{
var children = item.Children(c => c.IsVisible()).ToArray();
if (children.Any())
{
<div data-hover="1" data-delay="0" class="w-dropdown">
<div class="navlink w-dropdown-toggle">
<div>@item.Name</div>
</div>
@foreach (var child in children)
{
<nav class="w-dropdown-list">
<a href="@child.Url" class="navlink w-dropdown-link">@child.Name</a>
</nav>
}
</div>
}
else
{
<a href="@item.Url" class="navlink w-nav-link">@item.Name</a>
}
}
Hmm, and it's only rendering the latest added child-page to the sub nodes of the pages under the root?
A wild guess is that you have the umbracoNaviHide set to true? (IsVisible() filters those out)
Another option might be that it is hidden by some CSS or JavaScript on the front-end? You might want to check the source code on your page, just to be entirely sure :)
Dynamic Navigation Menu
Hi,
I'm trying to create a dynamic navigtaion menu as MegaNav isnt here for Umbraco8 yet.
I've got the following code which works fine for a single menu with no drop downs.
However, I want to add some dropdowns to the menus for nodes with children using the following html code;
Would anyone be able to help how I can add this to my code?
Thanks
Something like this any good?
Maybe it would be more efficient to do
Just to add on to the reply of Kieron, keep in mind that the suggested code contains a common pitfall (over-querying). A solution that solves this issue would be something like:
Yeah that looks much nicer. :)
Thanks thats great and worked a treat!
My only issue is it only shows 1 node in the drop down lists at a time? if I create more then 1 child under a node it will only show the latest 1?
Thanks
Hi Matt,
Glad it worked! Can you share the code you currently have? I think it should work with the code above, but I might be missing something!
Let me know and I will try to help you further :)
Thanks my code is below
Hmm, and it's only rendering the latest added child-page to the sub nodes of the pages under the root?
A wild guess is that you have the
umbracoNaviHide
set to true? (IsVisible()
filters those out)Another option might be that it is hidden by some CSS or JavaScript on the front-end? You might want to check the source code on your page, just to be entirely sure :)
Yeap thats correct, if I create a new child under node "what we do" it would then hide the previous child created.
I did think of the NaviHide, checked those and even tried removing the IsVisible statement but still the same issue.
Hmm I'll try check the CSS/JS but cant see it being an issue as works out of Umbraco, strange.
Got it working, I had to take the following class outside of my loop;
Thanks :)
Hi !! This solution worked for me
In master.cshtml
@{
var rootNodes = Umbraco.TypedContentAtRoot().ToList();
Layout = null;
}
Inside nav tag
In Master.css
is working on a reply...