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 am trying to create a generic site navigation partial view. It includes all levels recursively since that´s how I need it in the frontend.
However some document types are not meant to be part of the navigation. I take care of that in this code:
.Where(x => !(new[] { "doctype1", "doctype2" }).Contains(x.ContentType.Alias))
But I would like to declare it outside the helper method. I have started this in this line:
var excludeDocTypes = new[] { "doctype1", "doctype2" };
But how do I "pull" the excludeDocTypes variable into the helper method? That´s out of my current competences scope! ;)
@inherits Umbraco.Web.Mvc.UmbracoViewPage @{ var excludeDocTypes = new[] { "doctype1", "doctype2" }; } <nav> @RenderSubLevel(Model.Root()) </nav> @helper RenderSubLevel(IPublishedContent parent) { if (parent != null) { <ul class="[email protected]"> @foreach (var child in parent.Children(x => x.IsVisible()).Where(x => !(new[] { "doctype1", "doctype2" }).Contains(x.ContentType.Alias))) { <li> <a href="@child.Url" class="@(child.IsAncestorOrSelf(Model) ? "in-path" : null) @(child.Id == Model.Id ? "current" : null)"> @child.Url </a> @RenderSubLevel(child) </li> } </ul> } }
Hi Martin
The helper is 'self contained' but you can 'pass it in' if that makes sense:
@inherits Umbraco.Web.Mvc.UmbracoViewPage @{ var excludeDocTypes = new[] { "doctype1", "doctype2" }; } <nav> @RenderSubLevel(Model.Root(), excludeDocTypes) </nav> @helper RenderSubLevel(IPublishedContent parent, string[] excludeDocTypes) { if (parent != null) { <ul class="[email protected]"> @foreach (var child in parent.Children(x => x.IsVisible()).Where(x => !excludeDocTypes.Contains(x.ContentType.Alias))) { <li> <a href="@child.Url" class="@(child.IsAncestorOrSelf(Model) ? "in-path" : null) @(child.Id == Model.Id ? "current" : null)"> @child.Url </a> @RenderSubLevel(child, excludeDocTypes) </li> } </ul> } }
There's quite a good example of these kinds of razor shenanigans in the Razor 'xml site map' tutorial here: https://our.umbraco.com/documentation/Tutorials/Creating-an-XML-Site-Map/
regards
Marc
So cool - thnx! :)
It was the "string[]" part that I´d missed.
@inherits Umbraco.Web.Mvc.UmbracoViewPage @{ var excludeDocTypes = new[] { "doctype1", "doctype2" }; } <nav> @RenderSubLevel(Model.Root(), excludeDocTypes) </nav> @helper RenderSubLevel(IPublishedContent parent, string[] excludeDocTypes) { if (parent != null) { <ul class="[email protected]"> @foreach ( var child in parent.Children(x => x.IsVisible()). Where(x => !excludeDocTypes.Contains(x.ContentType.Alias)) ) { <li> <a href="@child.Url" class="@(child.IsAncestorOrSelf(Model) ? "in-path" : null) @(child.Id == Model.Id ? "current" : null)"> @child.Name </a> @RenderSubLevel(child, excludeDocTypes) </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.
Continue discussion
How to include a string list in LINQ query?
Hi,
I am trying to create a generic site navigation partial view. It includes all levels recursively since that´s how I need it in the frontend.
However some document types are not meant to be part of the navigation. I take care of that in this code:
But I would like to declare it outside the helper method. I have started this in this line:
But how do I "pull" the excludeDocTypes variable into the helper method? That´s out of my current competences scope! ;)
Hi Martin
The helper is 'self contained' but you can 'pass it in' if that makes sense:
There's quite a good example of these kinds of razor shenanigans in the Razor 'xml site map' tutorial here: https://our.umbraco.com/documentation/Tutorials/Creating-an-XML-Site-Map/
regards
Marc
So cool - thnx! :)
It was the "string[]" part that I´d missed.
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.