Copied to clipboard

Flag this post as spam?

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


  • Yannick Montalent 7 posts 87 karma points
    Jun 10, 2019 @ 05:27
    Yannick Montalent
    0

    Nodes with the same document type

    Hello,

    I need to get all nodes of a certain doctype that are children of the current page.

    I've not seen how to do this on Umbraco 8 and the way I used to do it in 7 is not applicable here.

    Is there a precise way of doing this?

    For now, I've been retrieving all children and then checking one by one for their doctype, not efficient at all.

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Jun 10, 2019 @ 08:09
    Marc Goodson
    0

    Hi Yannick

    Have you tried ChildrenOfType ?? extension method on IPublishedContent

    eg

    var childrenOfBlogType = Model.ChildrenOfType("blogPage");
    

    regards

    Marc

  • Yannick Montalent 7 posts 87 karma points
    Jun 12, 2019 @ 08:36
    Yannick Montalent
    0

    I was actually able to get everything using this:

    var selection = Model.Descendants().Where(x => x.IsDocumentType("xxx")).Where(y => y.IsVisible());
    
  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Jun 12, 2019 @ 10:18
    Marc Goodson
    0

    Hi Yannick

    Descendants... will pull all descendants into memory eg those below the children... (but sounds like in your circumstance there aren't any!)

    so be careful, in some circumstances you might find it's much more efficient to just use ChildrenOfType... and then you'll get only the children!

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft