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
HI,
I have a razor generated subnav, I am having issues with pages that have no sub nav items. I suppose I need to check the item exists, but my Razor knowledge is pretty sketchy.
My Code...
@using umbraco.MacroEngines@inherits DynamicNodeContext@{ var parent = @Model.AncestorOrSelf(1); <ul class="subnav"> @foreach (var item in @Model.AncestorOrSelf(2).Children.Where("Visible && umbracoNaviHide!=true")) { var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : string.Empty; <li@Html.Raw(selected)><a href="@item.Url"><span>@item.Name</span></a></li> } </ul> }
Hi Rocheh.
Try change the @Model.AncestorOrSelf(2) to parent.
Another point : umbracoNaviHide!=true and Visible is the same.
so :
@foreach (var item in parent.Children.Where("Visible")){ ..... }
Hope that help.
Cheers
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Subnav - check item exists
HI,
I have a razor generated subnav, I am having issues with pages that have no sub nav items. I suppose I need to check the item exists, but my Razor knowledge is pretty sketchy.
My Code...
@using umbraco.MacroEngines
@inherits DynamicNodeContext
@{
var parent = @Model.AncestorOrSelf(1);
<ul class="subnav">
@foreach (var item in @Model.AncestorOrSelf(2).Children.Where("Visible && umbracoNaviHide!=true"))
{
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : string.Empty;
<li@Html.Raw(selected)><a href="@item.Url"><span>@item.Name</span></a></li>
}
</ul>
}
Hi Rocheh.
Try change the @Model.AncestorOrSelf(2) to parent.
Another point : umbracoNaviHide!=true and Visible is the same.
so :
@foreach (var item in parent.Children.Where("Visible"))
{ ..... }
Hope that help.
Cheers
is working on a reply...