Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
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.
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
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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.
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
Hi,
You could try this:
You could also check maybe the Level of the current Node to check if its the root node. its faster.
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
is working on a reply...