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 39 posts 109 karma points
    May 03, 2024 @ 09:35
    apload-gmbh
    0

    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.

    Thanks,

    Jan

  • Garðar Þorsteinsson 119 posts 566 karma points
    May 03, 2024 @ 12:33
    Garðar Þorsteinsson
    100

    Hi,

    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 39 posts 109 karma points
    May 03, 2024 @ 14:33
    apload-gmbh
    0

    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

    Jan

  • 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