Copied to clipboard

Flag this post as spam?

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


  • Peter van Geffen 54 posts 290 karma points
    Jul 28, 2022 @ 09:04
    Peter van Geffen
    0

    Filter output based on a dropdown value

    Hi,

    I've got some projects and within them there's an option (dropdown) to choose a value what kind of project it is (Actueel - Toekomst).

    At the front-end in the homepage there are two sections. 'Actueel' projects & 'Toekomst' projects. I've got them separated in two similar partials.

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        var selection = Umbraco.Content(Guid.Parse("7e040147-9f94-4335-a0d7-b8260defcda9")).ChildrenOfType("project").Where(x => x.IsVisible());
    }
    <section class="highlight highlight-striped">
        <div class="container">
            <div class="row">
                @foreach (var item in selection.Take(3)){
                    if (item.Value<string>("werkzaamheid") == "Actueel"){
                        <div class="col-12 col-lg-4">
                            <a href="@item.Url" title="@item.Name" class="card border-0 rounded-0">
                                @if (item.Value<IPublishedContent>("afbeelding") != null){
                                    var image = item.Value<IPublishedContent>("afbeelding");
                                    <span class="card-img-top"><img src="@Url.GetCropUrl(image, "Maatregel")" alt="@image.Name" /></span>
                                }
                                <span class="card-body">
                                    @if (item.Value<string>("datum") != String.Empty){
                                        <span class="card-date">@item.Value("datum")</span>
                                    }
                                    <span class="card-title card-link h3">@item.Name</span>
                                </span>
                            </a>
                        </div>
                    }
                }
            </div>
        </div>
    </section>
    

    Is this the best way to do?

    Another problem i have is with the .Take() option. If the 'Actueel' items are 4,5,6 in line (back-end) it won't show anything. So I think it should be built or set up differently.

Please Sign in or register to post replies

Write your reply to:

Draft