Copied to clipboard

Flag this post as spam?

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

  • apload-gmbh 37 posts 107 karma points
    May 03, 2024 @ 09:35

    Model.Root() out of an Nested Content Element

    Hi there

    Our aim is to find out in a Nested Content Element if we are in the root (Home) of a website.

    In a Document Type View it is quite easy with i.e.

    var isHomepage = Model.Root().Id == Model.Id;

    But we struggle to do the same in a Nested Content Element. Does anybody can help us please.

    Maybe it is relevant that we still use Umbraco 9.



  • Garðar Þorsteinsson 114 posts 556 karma points
    May 03, 2024 @ 12:33
    Garðar Þorsteinsson


    You could try this:

    var currentNode = UmbracoContext.PublishedRequest.PublishedContent;
    var isRoot = currentNode.Root().Id == currentNode.Id;
    var isRoot = currentNode.Level == 1;

    You could also check maybe the Level of the current Node to check if its the root node. its faster.

  • apload-gmbh 37 posts 107 karma points
    May 03, 2024 @ 14:33

    Thanks Garðar

    I tried it with the first two code lines and it works for us as it should. You helped us a lot.

    Greetings from Switzerland


Please Sign in or register to post replies

Write your reply to: