Copied to clipboard

Flag this post as spam?

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


  • Doogie Talons 183 posts 318 karma points
    Apr 16, 2019 @ 12:32
    Doogie Talons
    0

    Help with property type in query

    Hi new to umbraco 8

    Not sure how to create a query which checks a property type.

    Used to just use.

    var footerNodes = CurrentPage.Site().Children.Where("footerNav == true");

    to get a list of nodes where the property type footerNav is checked.

    This is as far as I have got with the new umbraco... but its wrong.

    var selection = Umbraco.ContentAtRoot().FirstOrDefault()
    .Children()
    .Where(x => (x.HasValue<bool>("footerNav") == 1))
    .Where(x => x.IsVisible());
    

    Anyone know how I solver this ?

    Rob

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 16, 2019 @ 13:31
    Alex Skrypnyk
    100

    Hi

    Use this code:

    var selection = Umbraco.ContentAtRoot().FirstOrDefault()
        .Children()
        .Where(x => x.Value<bool>("footerNav"))
        .Where(x => x.IsVisible());
    

    Use "Value()" instead of "HasValue"

    HasValue is checking for null and emptiness.

  • Doogie Talons 183 posts 318 karma points
    Apr 16, 2019 @ 13:57
    Doogie Talons
    1

    Thanks :) works a charm.

    Rob

Please Sign in or register to post replies

Write your reply to:

Draft