Copied to clipboard

Flag this post as spam?

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


  • Clickfarm 77 posts 161 karma points
    Apr 21, 2015 @ 19:39
    Clickfarm
    0

    Get pages for multiple template types

    var articles = CurrentPage.AncestorOrSelf(1)
        .Descendants("GeneralArticle")
        .Where("Visible")
        .OrderBy("CreateDate desc")
        .Take(4)
        ;
    

    Descendants doesn't allow for multiple values here. How can I get a list of pages for multiple content types?

  • Clickfarm 77 posts 161 karma points
    Apr 21, 2015 @ 19:44
    Clickfarm
    0

    found another thread that answers it...

    var articles = CurrentPage.AncestorOrSelf(1)
        .Descendants()
        .Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "GeneralArticle", "ProjectArticle")
        .Where("Visible")
        .OrderBy("CreateDate desc")
        .Take(4)
        ;
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 21, 2015 @ 19:49
    Dennis Aaen
    0

    Hi Matt,

    If you are using Umbraco 7 as if I remember you need to use DocumeentTypeAlias instead of NodeTypeAlias. So the code would look like this:

    var articles = CurrentPage.AncestorOrSelf(1)
        .Descendants()
        .Where("DocumentTypeAlias == @0 || DocumentTypeAlias == @1", "GeneralArticle", "ProjectArticle")
        .Where("Visible")
        .OrderBy("CreateDate desc")
        .Take(4)
        ;

    Hope this helps,

    /Dennis

  • Clickfarm 77 posts 161 karma points
    Apr 21, 2015 @ 19:51
    Clickfarm
    0

    Hi Dennis,

    I am using umbraco 7.

    NodeTypeAlias appears to work, what's the difference between the two?

    Thanks

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 21, 2015 @ 19:58
    Dennis Aaen
    0

    Hi Matt,

    Don´t think there are any different and if it works for you with NodeTypeAlias, then it´s perfect. I was helping Claus with the same and he need to use the DocumentTypeAlias.

    Try to see this post. https://our.umbraco.org/forum/developers/razor/63939-Listing-nodes-of-multiple-doc-types

    /Dennis

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies