Im trying to show all the books from fiction/Non-ficition/You Decide, to pages Buy Fiction books/ Buy Non-Ficiton books/ Buy You Decide books/. I try to filter them throw ID of the Content, using Umbraco.Content(ID), but eventualy in case that content is deleted aint gona show no more, so im trying to to filter them throw property (bookgenre), of the document type BookItem.
I hope i was clear enough, Any Idea how this could be done !?
Its hard to say exactly what you should do because I can't see your template. One thing you can do is to put a Content Picker on each of those "Buy xxx books" pages where the content editor can pick the category of book that can be bought there. For the "Buy Non-fiction" page, the content editor would probably select the "fiction" node. That code might look like this:
var currentPage = Model.Content;
var bookCategoryFolderId = currentPage.GetPropertyValue<string>("bookCategory").
var bookCategoryFolder = Umbraco.TypedContent(bookCategoryFolderId);
var books = bookCategoryFolder.Children().Where(n =n.IsDocumentTypeAlias("BookItem"));
Using the bookgenre as you have said could also work. Instead of picking the folder node on your "Buy xxx books" pages, you could pick a book genre with your Book Genre datatype. You could do something like this:
var currentPage = Model.Content;
var bookGenre = currentPage.GetPropertyValue<string>("bookGenre");
var siteRoot = Umbraco.TypedContentAtRoot().First();
var books = siteRoot.Descendants().Where(n => n.IsDocumentType("BookItem") && n.GetPropertyValue<string>("bookgenre") == bookGenre);
You might not want to do it exactly that way. You probably don't need to traverse the entire content tree like I've done, but you could use some of the logic to accomplish what you are after.
that was my second idea as well, make a selection throw template ID, but that template is used by other pages as well, but i will try your example, tnx
Filter Collection by property of the Document type
Hi, this is my situation...
Im trying to show all the books from fiction/Non-ficition/You Decide, to pages Buy Fiction books/ Buy Non-Ficiton books/ Buy You Decide books/. I try to filter them throw ID of the Content, using Umbraco.Content(ID), but eventualy in case that content is deleted aint gona show no more, so im trying to to filter them throw property (bookgenre), of the document type BookItem.
I hope i was clear enough, Any Idea how this could be done !?
Its hard to say exactly what you should do because I can't see your template. One thing you can do is to put a Content Picker on each of those "Buy xxx books" pages where the content editor can pick the category of book that can be bought there. For the "Buy Non-fiction" page, the content editor would probably select the "fiction" node. That code might look like this:
Using the
bookgenre
as you have said could also work. Instead of picking the folder node on your "Buy xxx books" pages, you could pick a book genre with yourBook Genre
datatype. You could do something like this:You might not want to do it exactly that way. You probably don't need to traverse the entire content tree like I've done, but you could use some of the logic to accomplish what you are after.
that was my second idea as well, make a selection throw template ID, but that template is used by other pages as well, but i will try your example, tnx
is working on a reply...