Copied to clipboard

Flag this post as spam?

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


  • suzyb 474 posts 932 karma points
    May 01, 2014 @ 19:01
    suzyb
    0

    finding pages where descendants have certain property

    How do I select the pages where the descendants have a certain property value.

    For example I have this tree and I'd like to get only the location pages where the course type page have property value a.

    -- location
    ---- page
    ------ course type with property value a
    -- location
    ---- page
    ------ course type with property value b

    Is such a thing possible in one statement or would I need to select all the locations and loop through them then only select the ones that have the property value I want.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 02, 2014 @ 00:04
    Jeavon Leopold
    0

    Hi Suzy,

    Yes it is, in the below example we look at properties with the alias "superHero" and get returned a collection of items where they that property has the value "SuperMan"

    @{
        var valueToMatch = "SuperMan";
    
        var home = CurrentPage.AncestorOrSelf(1);
        if (home != null)
        {
            var articles = home. Descendants.Where("superHero.ToLower() == @0", 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>
            }
        }
    }
    

    Hope that's helpful?

    Jeavon

  • suzyb 474 posts 932 karma points
    May 02, 2014 @ 11:27
    suzyb
    0

    Thanks that helps me with the syntax of the where statement.

    It will give me the list of descendants though.  I need a list of the higher level pages, in your example those at the home level.  Think I'm going to have to loop through the location pages to do that.

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 02, 2014 @ 12:03
    Jeavon Leopold
    0

    Hi Suzy, The example will filter all descendants of the home, which would normally be your entire site. Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft