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
So the idea is that this can be used to pull page the visible pages, or nodes... e.g. the ones that don't have umbracoNaviHide set.
However, it seems to also bring back nodes which don't have a template?
I've tried:
x => x.TemplateId != -1 x => x.TemplateId > 1000
x => x.TemplateId != -1
x => x.TemplateId > 1000
But I've got a pesky page, that once had a template, that keeps coming back, dang!
So, what is the best way to filter out the nodes which do not have a template?
@foreach (var item in nodes.Where("Visible").Where(x => x.TemplateId != -1)) { <li class="@(item.IsAncestorOrSelf(Model.Content) ? "active" : null)"> <a href="@item.Url">@item.Name</a> </li> }
Ideas!
Also if Umbraco is going to have this magic .Where('visible') which abstracts umbracoNaviHide perhaps it should also exclude pages with out templates (e.g. no URLs).
.Where('visible')
umbracoNaviHide
Over and out! Laurie
Hi Laurie
Your code doesn't work because you are using dynamic types, can you use strongly typed?
It works with strongly typed nodes collections - https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/Collections#filtering-ordering-extensions
Thanks,
Alex
If you're familiar with C# extension methods then a nice way to do this is to create one like this:
public static bool HasTemplate(this IPublishedContent content) { return content.TemplateId > 0; }
Then, I'd suggest using typed queries (like Alex mentions). You can then do stuff like this:
@foreach (var item in nodes.Where(x => x.IsVisible() && x.HasTemplate()) { }
You can even add another extension method to make it neater:
public static bool IsInListing(this IPublishedContent content) { return this.IsVisible() && this.HasTemplate(); }
Then you just go:
@foreach (var item in nodes.Where(x => x.IsInListing()) { }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Umbraco .Where("visible")
So the idea is that this can be used to pull page the visible pages, or nodes... e.g. the ones that don't have umbracoNaviHide set.
However, it seems to also bring back nodes which don't have a template?
I've tried:
x => x.TemplateId != -1
x => x.TemplateId > 1000
But I've got a pesky page, that once had a template, that keeps coming back, dang!
So, what is the best way to filter out the nodes which do not have a template?
Ideas!
Also if Umbraco is going to have this magic
.Where('visible')
which abstractsumbracoNaviHide
perhaps it should also exclude pages with out templates (e.g. no URLs).Over and out! Laurie
Hi Laurie
Your code doesn't work because you are using dynamic types, can you use strongly typed?
It works with strongly typed nodes collections - https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/Collections#filtering-ordering-extensions
Thanks,
Alex
If you're familiar with C# extension methods then a nice way to do this is to create one like this:
Then, I'd suggest using typed queries (like Alex mentions). You can then do stuff like this:
You can even add another extension method to make it neater:
Then you just go:
is working on a reply...