Below also will work; however, it is leveraging LINQ as opposed to xpath, so you might read up on https://our.umbraco.com/documentation/Reference/Common-Pitfalls/. I am not sure if the statements regarding LINQ/Xpath still apply, but they are certainly worth keeping in mind.
Get Content of a particular document type
Hi,
Is there a way to get all content nodes of a particular document type?
Sure it should be simple but can't seem to find anything for V8.
Many thanks,
Andrew
IENumerable<IPublishedContent> allContentOfType = Umbraco.ContentAtXpath("//documentTypeAlias")
should still work.I don't know how it performs in V8.
Below also will work; however, it is leveraging LINQ as opposed to xpath, so you might read up on https://our.umbraco.com/documentation/Reference/Common-Pitfalls/. I am not sure if the statements regarding LINQ/Xpath still apply, but they are certainly worth keeping in mind.
Andrew, I guess you are looking for "DescendantsOfType"? Model.DescendantsOfType("myDocType")
I think descendants is more expensive than the xpath solution. It searched the entire tree and gets the items you are looking for.
Xpath gets the types directly from cache. At least in v7
XPath is a good option, I'm using it on a site I'm building at the moment, as an example in my layout file I have:
I then pass the ID to another class to return some data.
If you have a quick look at https://our.umbraco.com/documentation/Reference/Common-Pitfalls/ and have a quick read of Too much LINQ - XPath is still your friend which explains XPath well
Thanks for your help guys, using Xpath did the job. Much appreciated and thanks for the extra links, will give them a read :)
is working on a reply...