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 2 posts 72 karma points
    1 week ago
    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 878 posts 5733 karma points MVP 4x c-trib
    1 week ago
    Marc Goodson
    0

    Hi Yannick

    Have you tried ChildrenOfType ?? extension method on IPublishedContent

    eg

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

    regards

    Marc

  • Yannick Montalent 2 posts 72 karma points
    7 days ago
    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 878 posts 5733 karma points MVP 4x c-trib
    7 days ago
    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