Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a problem creating a subnavigation i razor, thats shows parent along with the childpages. I have a structure like this:
When you click on "Services", I need the subnavigation to show not only the childpages (service 1, service 2 etc.) but also the parent "Services".
I am using the standard Razor template for navigations, but I don't know how to customize it to also include the parent. Heres my Razor script:
@*Get the root of the website *@
var root = Model.AncestorOrSelf(2);
@foreach (var page in root.Textpages.Where("Visible"))
<a class="@page.IsAncestorOrSelf(Model, "current", "")" href="@page.Url">@page.name</a>
Can someone please help me out?
You could simply 'hard-code' the first item using root, something like below.
Also, just to note that you probably want to null check your variables here so I've added that in to the example aswell. Finally, I'm using Children here as I'm running Umbraco 7.7 and TextPages throws an error.
var root = Model.Content.AncestorOrSelf(2);
@if (root != null)
if (root.Children != null && root.Children.Any())
foreach (var child in root.Children)
<a class="@child.IsAncestorOrSelf(Model.Content, "current", "")" href="@child.Url">@child.Name</a>
Perfect - Thats solved my problem. Thank you, Ben :)
-- Big high five --
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted