Copied to clipboard

Flag this post as spam?

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


  • Matt 353 posts 825 karma points
    Oct 31, 2019 @ 15:20
    Matt
    0

    display nodes if Tag has x value

    Hello,

    So I have a doctype and I'm using the following query to show the all the nodes which works fine.

    @{
        var selection = Umbraco.Content(Guid.Parse("5c3471d3-b088-4d67-8188-0a9795a3c93e"))
        .Children()
        .Where(x => x.IsVisible());
    }
    <ul>
        @foreach (var item in selection)
        {
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    However what I want to do is I've got a tag property called "boardType" and I want to only show nodes where the tag is called e.g Executive how could I achieve this?

    Thanks

  • Bo Jacobsen 597 posts 2395 karma points
    Oct 31, 2019 @ 15:30
    Bo Jacobsen
    0

    Hi Matt.

    This is untested, but i think you can extend your where clause with this.

    .Where(x => x.IsVisible() && x.Value<string[]>("boardType").Contains("Executive"));
    

    If you are using culture variants you need to add culture to the value after "boardType" like x.Value<string[]>("boardType", "en-US")

  • Matt 353 posts 825 karma points
    Nov 01, 2019 @ 10:16
    Matt
    0

    Thats perfect thanks, if I wanted to do same for dropdown would I simply use same code but just change the property name?

  • Bo Jacobsen 597 posts 2395 karma points
    Nov 01, 2019 @ 13:57
    Bo Jacobsen
    0

    I think the dropdown represents a string so it would be something like this x.Value<string>("boardType") == "Executive"

Please Sign in or register to post replies

Write your reply to:

Draft