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
    16 days ago
    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 114 posts 556 karma points
    16 days ago
    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 37 posts 107 karma points
    16 days ago
    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

Please Sign in or register to post replies

Write your reply to:

Draft