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
    Aug 22, 2019 @ 05:23
    Yannick Montalent
    0

    Get root node

    I'm trying to get a specific content node with a specific document type. This content node is a root node and I do have 2 other nodes at root level.

    This is my hierarchy in the backend content section:

    • EN
      • Page 1
      • Page 2
      • Page 3
    • Details
    • Error

    How do I get the data from the Details node in a template connected to the EN node using razor?

  • Sören Deger 726 posts 2833 karma points c-trib
    Aug 22, 2019 @ 06:15
    Sören Deger
    100

    Hi Yannick, you can use .Siblings(), and if you are not at level 1, you can go up at first with .Root():

    var detailsNode = Model.Root().Siblings().FirstOrDefault(x => x.ContentType.Alias == "docTypeAlias");
    

    Replace the string "docTypeAlias" with the alias of your Details Node.

    Best, Sören

  • Yannick Montalent 7 posts 87 karma points
    Aug 22, 2019 @ 07:39
    Yannick Montalent
    0

    Thanks Sören,

    works perfectly!

  • Enkosi 8 posts 80 karma points
    Dec 10, 2020 @ 12:55
    Enkosi
    0

    For Umbraco 8 you can try:

    var rootNode = Umbraco.Web.Composing.Current.UmbracoHelper.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == "docTypeAlias");
    
  • hakan 20 posts 111 karma points
    Feb 15, 2021 @ 09:57
    hakan
    1

    Model.Root().SiblingsAndSelf() => it gets all root pages

    Model.Root() => it gets just current page root

  • 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