I need some help with a menu. I created a Umbraco 6.1.6
You can view a html dummie of what I am looking for here: http://wasteofspace.dk/version4/ The menu will function as follows: - The menu consists of max 4 levels (ex. Categories -> Css is a fix ... -> Css Item 14) - Menu item should only be clickable if there is no underneath menu-item - The last menu item should of course be clickable
I have taking a look on your HTML dummy and I think that I have some code that maybe could help you.
As I remember youusually use the old dynmaic razor node, is it alsothe case here,if not let me know then. You could try something like this;
@inherits umbraco.MacroEngines.DynamicNodeContext @{ @*Get the root of the website *@ var root =Model.AncestorOrSelf(1); var naviLevel =Model.Level(); } <nav id="menu-wrap"> <ul id="menu"class="level-@naviLevel"> @foreach(var childPage in root.Children.Where("Visible")) { <li> <img alt="menu navn" src="images/ikon1.png"> <a href="@childPage.Url">
<h2>@childPage.Name</h2> <span>Menu text</span>
</a> @* if the current page has any children, where the property umbracoNaviHide is not True *@ @if (childPage.Children.Where("Visible").Any()) { @* Call our helper to display the children *@ @childPages(childPage.Children) } </li> } </ul> </nav>
@helper childPages(dynamic pages) { @*Ensure that we have a collection of pages *@ if(pages.Any()) { @*Get the first page in pages andget the level *@ var naviLevel = pages.First().Level; @*Addin level for a CSS hook *@
@*if the current page has any children,where the property umbracoNaviHide isnotTrue*@ @if(page.Children.Where("Visible").Any()) { @*Callour helper to display the children *@ @childPages(page.Children) } </li> } </ul> } }
And depending on the content structure, you will ned to make some small changes. I my case I start at level 1. But if you for instance have an multi language site, and the first node are the languages you need to change it to var root = Model.AncestorOrSelf(2).
Another menu problem
Hi
I need some help with a menu.
I created a Umbraco 6.1.6
You can view a html dummie of what I am looking for here: http://wasteofspace.dk/version4/
The menu will function as follows:
- The menu consists of max 4 levels (ex. Categories -> Css is a fix ... -> Css Item 14)
- Menu item should only be clickable if there is no underneath menu-item
- The last menu item should of course be clickable
Hope you can help me ☺
Hi Kate,
I have taking a look on your HTML dummy and I think that I have some code that maybe could help you.
As I remember you usually use the old dynmaic razor node, is it also the case here,if not let me know then. You could try something like this;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
@*Get the root of the website *@
var root =Model.AncestorOrSelf(1);
var naviLevel =Model.Level();
}
<nav id="menu-wrap">
<ul id="menu"class="level-@naviLevel">
@foreach(var childPage in root.Children.Where("Visible"))
{
<li>
<img alt="menu navn" src="images/ikon1.png">
<a href="@childPage.Url">
<h2>@childPage.Name</h2>
<span>Menu text</span>
</a>
@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("Visible").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children)
}
</li>
}
</ul>
</nav>
@helper childPages(dynamic pages)
{
@*Ensure that we have a collection of pages *@
if(pages.Any())
{
@*Get the first page in pages andget the level *@
var naviLevel = pages.First().Level;
@*Addin level for a CSS hook *@
<ul class="level-@naviLevel">
<li class="columHeadline">overskrift 1.1</li>
@foreach (var page in pages.Where("Visible"))
{
<li>
<a href="@page.Url">@page.Name</a>
@*if the current page has any children,where the property umbracoNaviHide isnotTrue*@
@if(page.Children.Where("Visible").Any())
{
@*Callour helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
}
}
And depending on the content structure, you will ned to make some small changes. I my case I start at level 1. But if you for instance have an multi language site, and the first node are the languages you need to change it to var root = Model.AncestorOrSelf(2).
Hope this helps,
/Dennis
Hi Dennis
It works perfectly.
As you mentioned I have to change the Model.AncesterOrSelft and I have added a few classes. But it works.
Thanks for your help :-)
/Kate
is working on a reply...