Copied to clipboard

Flag this post as spam?

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


  • Clare 37 posts 117 karma points
    Nov 08, 2013 @ 12:32
    Clare
    0

    Razor - how to list descendants from multiple lists

    I'm trying to create a macro to list descendants of a particular document type no matter where they are in the content tree. At the moment it only traverses through the first list (in this instance the UG study list) but I need it to travel both lists:

    -Main
    ---UG study (programmeList)
    ......programme 1
    ......programme 2
    ---PG study (programmeList)
    ......programme 1
    ......programme 2

    How do I get it to get any document types not just from the first list?

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
        string schoolToFind = Parameter.ProgrammeSchool;
        var root = Model.AncestorOrSelf();
        var programmeNames = root.Descendants("ProgrammeList").First();
           
           <div>
            @foreach (var item in programmeNames.Children.OrderBy("programmeName"))
            {
                 string[] school = item.school.ToString().Split(',');
               
                if (school.Contains(schoolToFind))
                    {
                        <li>
                        <a href="@item.Url">@item.programmeName - @item.qualificationType</a>
                        </li>
                        }
               
                             }
        </div>
               
    }
  • Marcio Goularte 374 posts 1346 karma points
    Nov 08, 2013 @ 12:52
    Marcio Goularte
    100

    Hi,

    I changed your code. Now the query will get all doctype Programme

    @using umbraco.MacroEngines
    @inheritsDynamicNodeContext
    @{
       
    string schoolToFind =Parameter.ProgrammeSchool;
       
    var root =Model.AncestorOrSelf(1);
       
    var programmeNames = root.DescendantsOrSelf("programme").OrderBy("programmeName").ToList();
           
           
    <div>
           
    @foreach(var item in programmeNames)
           
    {
                 
    string[] school = item.school.ToString().Split(',');
               
               
    if(school.Contains(schoolToFind))
                   
    {
                       
    <li>
                       
    <a href="@item.Url">@item.programmeName -@item.qualificationType</a>
                        li>
                       
    }
               
                             
    }
       
    div>
               
    }
  • Clare 37 posts 117 karma points
    Nov 08, 2013 @ 13:33
    Clare
    0

    Thank you so much it works now :)

Please Sign in or register to post replies

Write your reply to:

Draft