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 731 posts 2841 karma points c-trib
    Aug 22, 2019 @ 06:15
    Sören Deger
    101

    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!

  • ewuski 16 posts 116 karma points
    28 days ago
    ewuski
    0

    Very useful. Saved my life as I had to find a root within a partial model and couldn't use UmbracoHelper

  • Enkosi 9 posts 83 karma points
    Dec 10, 2020 @ 12:55
    Enkosi
    1

    For Umbraco 8 you can try:

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

    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