Copied to clipboard

Flag this post as spam?

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


  • Danny 15 posts 136 karma points
    Apr 10, 2015 @ 20:09
    Danny
    0

    Descendants(String) stops returning expected nodes after child of descendant gets published

    I'm trying to replace the places in my templates where I look up nodes by nodeId to look up nodes by their documentType and where they appear in the node hierarchy.

    // original reference
    var content = Umbraco.Content(1000);
    
    // new version
    var current = CurrentPage.AncestorOrSelf();
    var content = current.Descendants("ContentDocumentType");
    

    The new version works inconsistently. If I leave the Umbraco.Content(1000) above the new code (without declaring content), then current.Descendants("ContentDocumentType") returns something, but if I remove that line and publish a different node (specifically a childnode of the ContentDocumentType node), then current.Descendants("ContentDocumentType") returns an empty collection.

    Why does current.Descendants("ContentDocumentType") behave inconsistently?

    Is there a better way to retrieve nodes without looking them up by nodeId?

    Thanks in advance.

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Apr 10, 2015 @ 20:33
    Jeavon Leopold
    100

    Hi Danny,

    Have you tried specifying the level as 1? e.g.

    var current = CurrentPage.AncestorOrSelf(1);
    

    Jeavon

  • 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