Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Oct 13, 2017 @ 21:28
    blackhawk
    0

    How to include child nodes in determining which pages has a dropdown value?

    In regards to the third example described here for dropdowns. How can we expand the following code to include child nodes that have dropdown values assigned to them?

    @{
        var valueToMatch = "SuperMan";
        //Get the first node inside the root
        var firstTypedContentAtRoot = Umbraco.TypedContentAtRoot().FirstOrDefault();
        if (firstTypedContentAtRoot != null)
        {
            var articles = firstTypedContentAtRoot.Children.Where(x => x.HasValue("superHero") && x.GetPropertyValue<string>("superHero").ToLower().Contains(valueToMatch.ToLower()));
            if (articles.Any())
            {
                <p>Pages with @valueToMatch selected:</p>
                <ul>
                    @foreach (var page in articles)
                    {
                        <li><a href="@page.Url"> @page.Name</a></li>
                    }
                </ul>
            }
        }
    }
    

    For example, in the starter kit of Umbraco 7.6.6,

    1. I modified my content page document type to include a dropdown with 4 pre-defined values.
    2. I then assigned the About Us and About this Starter Kit content nodes with the dropdown value "Jacket".

    FYI - Both the About Us and About this Starter Kit content nodes share the same document type.

    ...But with the above code, Umbraco only recognizes the About Us with the value Jacket.

    Any thoughts?

Please Sign in or register to post replies

Write your reply to:

Draft