[Solved] How to get Sibling Root node in a ViewCom...
# help-with-umbraco
c
Umb 10.6.1 Site has it's Home root and a separate Site Settings root as a sibling to the Home root. In a ViewComponent, I have an UmbracoContext and can get the site root ok, but how do I get to it's sibling SiteSettings? Anything I try fails. Rider isn't suggesting a using.
m
GetAtRoot() is all the root nodes, as its an IEnumerable GetAtRoot().OfType().FirstOrDefault()
h
this is the code I use to generate my site menu
Copy code
cs
    var rootContent = Umbraco.ContentAtRoot();
    var siteRoot = (IPublishedContent)rootContent.FirstOrDefault();
    var children = siteRoot?.Children(x => x.IsVisible());
    var siblings = siteRoot?.Siblings()?.Where(x => x.IsVisible());
c
Hmmmm, just Umbraco.ContentAtRoot() doesn't work here. I have to inject IUmbracoContextFactory to get an UmbracoContext. Were you in a ViewComponent though?
h
Ah, no I'm in a Partial View
m
IUmbracoContextAccessor also works instead of the factory
m
you might also be able to inject an umbracohelper. https://docs.umbraco.com/umbraco-cms/reference/using-ioc#umbracohelper
7 Views