Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Laurence Gillian 595 posts 1212 karma points
    Jun 28, 2017 @ 10:54
    Laurence Gillian

    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?

    @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>


    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).

    Over and out! Laurie

  • Alex Skrypnyk 5733 posts 21736 karma points MVP 4x admin c-trib
    Jun 28, 2017 @ 11:35
    Alex Skrypnyk

    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 -



  • Dan Diplo 1490 posts 5790 karma points MVP 4x c-trib
    Jun 28, 2017 @ 12:51
    Dan Diplo

    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())
Please Sign in or register to post replies

Write your reply to: