Get items from parent node only
t
Hi I have two domains in my Umbraco. I want to get all items by the document type Credit. Presently, I have the code in my controller UmbracoContext.Content.DescendebtsOrSelf Which does what I need until I added a second domain in which case it's now bringing everything from the main domain and the second domain. I'm trying to limit this by the domain/parent node but I can't find something equivalent of this. Does anyone know how I'm supposed to retrieve by parent only? Thank you
l
Hullo ^^ Just a clarifying question: these 'parents', are they separate root nodes in the tree? Or is the node with the 2nd domain nested below 1st?
a
You could first get the
ContentAtRoot()
which matches your domain, or depending on where you need this (example: in Partial Views you can just get the homepage from your Context, and do` home.DescendantsOrSelf()`
t
Hi so something like this -HomeOne --Credit -List Goes here for home one -HomeTwo --Credit -List Goes here for home two Not sure if that is any clearer
Hi this is in a controller but I don't see the option, ContentAtRoot?
a
context.Content.GetAtRoot()
if im correct
But depending on the type of controller, you can also get the publishedrequest (so the current page), and loop from there
t
Sorry I had a typo in my original code. I am using GetAtRoot UmbracoContext.Content.GetAtRoot...... But that seems to get everything off Credit regardless where the content resides. It's a RenderController
a
If its RenderController, can you use
CurrentPage
right?
Then you could do
CurrentPage.AncestorOrSelf<HomePage>().Descendants<Credit>()
Basically, go to your current site root, and then find the items
t
Let me try that 👍
4 Views