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
    14 days ago
    hakan
    1

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

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

Please Sign in or register to post replies

Write your reply to:

Draft