Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm having trouble retrieving all contents based on the document type.
I have the following hierarchy in my Content section:
I need to retrieve only the content under the node Tours and all three of the have the same Document Type " tourType "
I used to do it like this on Umbraco 7:
var tours = Model.Content.Children(x=>x.DocumentTypeAlias=="tourType").Where("Visible");
How should it be done now in 8?
in Umbraco 8 you should be able to achieve this using following:
var tours = Model.Children<TourType>().Where(x => x.IsVisible());
Not strongly typed:
var tours = Model.Children(x => x.IsDocumentType("tourType") && x.IsVisible());
Hope I could help you.
I've tried your solution.
However, it's still not working for me.
I get a compilation error:
Compiler Error Message: CS0246: The type or namespace name 'TourType' could not be found (are you missing a using directive or an assembly reference?)
I've changed this value with the document type id and even tried others and I'm still not getting any results.
What am I doing wring here?
In addition to the suggestions above there is a 'ChildrenOfType' extension on IPublishedContent that you could also use:
var tours = Model.ChildrenOfType("tourType").Where(f=>f.IsVisible());
It might work with:
var content = Model.Content.Site().FirstChild("tours");
Then you can access children etc.
Testing the ChildrenOfType extension in 8.1.0 doesn't work, it just returns the same result with Children, that is all children. I guess this is a bug.
My only success was with:
var categories = parentNode.Children(c => c.IsDocumentType("category"));
var categories = parentNode.Children(c => c.ContentType.Alias == "category");
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted