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 05, 2014 @ 19:03
    Clare
    0

    Razor - how to list descendants from multiple lists and multiple doc types

    HI there,

    Currently we use the following script to make lists of events document types no matter where they appear in the content tree. We have a new event doc type (alias RecruitmentEvent) and so we now need this list to pick up both doc types - Eventspage and RecruitmentEvent.

    I've tried changinging this line 

    var newsEvents = root.DescendantsOrSelf("Eventspage").ToList();

    to:

    var newsEvents = root.DescendantsOrSelf("Eventspage||RecruitmentEvent").ToList();

    but that didn't work so I must be missing something! This is the full script we currently have:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
    string tagToFind = Parameter.EventType;
        var root = Model.AncestorOrSelf(1);
    var newsEvents = root.DescendantsOrSelf("Eventspage").ToList();
            
           

            @foreach (var item in newsEvents.Where("startDateAndTime >= @0", DateTime.Now.Date).OrderBy("startDateAndTime"))
            {
    string[] tags = item.tags.ToString().Split(',');

    if (tags.Contains(tagToFind))
        {
               



    @if(@item.eventName.ToString() != string.Empty){
       

    @item.eventName


    }else{
       

    @item.Name


    }

    @item.startDateAndTime.ToString("dd MMM yyyy")


    @item.Summary

    ›› Read more




        }

    }


    }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 05, 2014 @ 19:16
    Dennis Aaen
    100

    Hi Clare,

    What if you try to change:

    var newsEvents = root.DescendantsOrSelf("Eventspage").ToList();

    To this:

    var newsEvents = root.DescendantsOrSelf().Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "Eventspage", "RecruitmentEvent").ToList();

    So your full script would look like this.

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
        string tagToFind = Parameter.EventType;
        var root = Model.AncestorOrSelf(1);
        var newsEvents = root.DescendantsOrSelf().Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "Eventspage", "RecruitmentEvent").ToList();
       
           
           <div>
            @foreach (var item in newsEvents.Where("startDateAndTime >= @0", DateTime.Now.Date).OrderBy("startDateAndTime"))
            {
              string[] tags = item.tags.ToString().Split(',');
             
               if (tags.Contains(tagToFind))
                    {
                       
                       <div class="row">
            <div class="span8 @item.IsLast("no-border")">
               
               @if(@item.eventName.ToString() != string.Empty){
        <h3><a style="text-decoration:none" href="@item.Url">@item.eventName</a></h3>
    }else{
        <h3><a style="text-decoration:none" href="@item.Url">@item.Name</a></h3>
    }
              
               <p>@item.startDateAndTime.ToString("dd MMM yyyy")</p>
              <p>@item.Summary<br/>
                      ›› <a href="@item.Url" title="@item.HeaderText">Read more</a></p>
          </div>
       </div>
                      }
            
                            }
     </div>
              
    }

    Hope this helps,

    /Dennis

  • Clare 37 posts 117 karma points
    Nov 05, 2014 @ 19:32
    Clare
    0

    Thanks so much Dennis, works perfectly!

Please Sign in or register to post replies

Write your reply to:

Draft