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
Matt Wise
08/31/2023, 9:16 AM
GetAtRoot() is all the root nodes, as its an IEnumerable GetAtRoot().OfType().FirstOrDefault()
h
huwred
08/31/2023, 9:21 AM
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
Craig100
08/31/2023, 9:41 AM
Hmmmm, just Umbraco.ContentAtRoot() doesn't work here. I have to inject IUmbracoContextFactory to get an UmbracoContext. Were you in a ViewComponent though?
h
huwred
08/31/2023, 9:42 AM
Ah, no I'm in a Partial View
m
Matt Wise
08/31/2023, 9:52 AM
IUmbracoContextAccessor also works instead of the factory