Copied to clipboard

Flag this post as spam?

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


  • Jack Taylor 16 posts 107 karma points
    Mar 10, 2021 @ 15:59
    Jack Taylor
    0

    Query list by select property

    Hello,

    I'm currently trying to query a listing to get all the children that have a certain property entered. The property is a select property with 4 different values.

    So far I've managed to check if the item has a property value by adding:

    .Where(x => x.HasValue("sessionDay"));
    

    Now I want to check if that value equals "Day 1 AM" or "Day 1 PM" for example, two of the select options.

            <div class="row">
            @{
                var selection = Umbraco.Content(Guid.Parse("8c1a3109-8cb1-4c8d-a7b6-ea3b0ba7d704"))
                .Children()
                .Where(x => x.IsVisible())
                .Where(x => x.HasValue("sessionDay"));
            }
            @foreach (var item in selection)
            {
                <div class="col-12 col-md-4 my-5 d-flex flex-column">
                    <p class="session-listing-number">@item.Name</p>
                    @if (item.HasValue("sessionDate"))
                    {
                        <p class="session-listing-date">@(item.Value<DateTime>("sessionDate").ToString("dddd dd MMMM, H:mm tt"))</p>
                    }
                    <a href="@item.Url"><h3>@item.Value("longTitle")</h3></a>
                    <p>@item.Value("sessionExcerpt")</p>
                    <a href="@item.Url" class="btn btn-primary mt-auto">View session</a>
                </div> 
            }
        </div>  
    

    Can anyone help me with what to add to the above code to add a line to the query to only get children with the property value "Day 1 AM"?

    Or the better alternative might be to change the for each statement, var item in selection where sessionDay = Day 1 AM? Not quite sure how to write that?

    Thanks in advance for any help

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Mar 10, 2021 @ 18:07
    Huw Reddick
    0

    You should be able to just use a where clause like below

    where(x=>X.Value("sessionDate")=="Day 1 AM")

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Mar 10, 2021 @ 18:09
    Huw Reddick
    0

    Sorry misread your question so ignore my answer, although you could possibly advit to your for each to just show them based on the name of your item

Please Sign in or register to post replies

Write your reply to:

Draft