Copied to clipboard

Flag this post as spam?

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


  • Sidz 4 posts 94 karma points
    Feb 19, 2019 @ 12:28
    Sidz
    0

    Accesing the content from immediate parent

    I am trying to access content from my level 2 document type from a sub level. level 2 has multiple pages of same document type. I am using the code below

     var rootByTraversing = Umbraco.AssignedContentItem.AncestorOrSelf(2);
        var openingTimesByDescendants = rootByTraversing.Descendants().Where(f => f.DocumentTypeAlias == "PageLevel2").FirstOrDefault();
    

    Is it possible for me to get the immediate parent node of this document type and not FirstOrDefault node?

    I don't want to access the content through node id.

  • Sven Geusens 169 posts 881 karma points c-trib
    Feb 20, 2019 @ 11:06
    Sven Geusens
    1

    Umbraco.AssignedContentItem returns an IPublishedContent

    To get the parent of a node represented as an IPublischedContent call .Parent To go higher up the tree, use .AncestorOrSelf(1basedIndexOfTheLevelYouWantToReach)

    Try and avoid using .Descendants() because it loads in all nodes below the one you are calling from, this can have serious performance implications on bigger sites.

Please Sign in or register to post replies

Write your reply to:

Draft