Finding the home node
# help-with-umbraco
t
Hi I have an Umbraco 13 with a structure like this Website(primary) Site A Site B Website(secondary) Website(tertiary) When the user arrives to any level I want to get some content which is on Website(primary). At the moment I have managed to partially do this by using the domains service but this doesn't seem to work fully. How could I always get to the primary website no matter how I reach the site? Thank you
d
Hi there! Assuming your Website nodes are in the root of the content tree, you could simply access the
ContentAtRoot
from an
UmbracoContext
. In controllers and views, you usually have access to Umbraco context, but you can also find it with
IUmbracoContextAccessor
.
I think
ContentAtRoot
returns the root content in the order that you see them in the backoffice, but it may be appropriate to give your primary site some distinct property by which you can recognize it.
t
I don't see ContentAtRoot anywhere. Could I be missing something else?
d
Do you have access to an Umbraco context?
From the top of my head, it's:
Copy code
var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
var contentAtRoot = umbracoContext.Content.GetContentAtRoot();
t
Let me try again..... Is this for Umbraco 13?
d
Yeah, should be. I'm using this in my Umbraco 13 site
8 Views