Hi I'm creating a website in version 5 and am very new to Razor.
I want a multi level navigation, something that will display the first 3 levels in the content tree.
Is anyone able to help me with this, I just need to gain a better understanding of Razor. Also I don't want the Homepage node as the variable. I just want a simple nav that can display all the items at level one, then nest levels 2 and 3 within it.
I'm using the following following code from the version 5.0.1 install starter package:
@inherits RenderViewPage @using Umbraco.Cms.Web;
@{ var Homepage = @DynamicModel; while (Homepage.ContentType.Alias != "homePage") { Homepage = Homepage.Parent; } } <ul class="dropdown"> <!--<li><a href="@Homepage.Url">Home</a></li>--> @foreach (var item in Homepage.Children) { if (@item.CurrentTemplate != null) { var childName = item.Name ?? "(No name yet)"; <li><a href="@item.Url">@childName </a></li> } } </ul>
Umbraco Version 5 Multi Level navigation Razor
Hi I'm creating a website in version 5 and am very new to Razor.
I want a multi level navigation, something that will display the first 3 levels in the content tree.
Is anyone able to help me with this, I just need to gain a better understanding of Razor. Also I don't want the Homepage node as the variable. I just want a simple nav that can display all the items at level one, then nest levels 2 and 3 within it.
I'm using the following following code from the version 5.0.1 install starter package:
This is a way to get what you want, but might not the best one:
@{ var topLevel = this.Model.AncestorContentOrSelf().Where(n => n.ParentContent() == null); <ul> @* level 1 *@ @foreach (var item in topLevel) { <li> 1- @item.Name <ul> @foreach (var level2Item in item.ChildContent()) { <li> 2- @level2Item.Name <ul> @foreach (var level3Item in level2Item.ChildContent()) { <li> 3 - @level3Item.Name </li> } </ul> </li> } </ul> </li> } </ul> }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.