Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • aleksandar 14 posts 74 karma points
    Aug 21, 2015 @ 12:44
    aleksandar
    0

    Filter Collection by property of the Document type

    Hi, this is my situation... enter image description here

    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 !?

  • Mark Bowser 273 posts 860 karma points c-trib
    Aug 21, 2015 @ 16:36
    Mark Bowser
    0

    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.

  • aleksandar 14 posts 74 karma points
    Aug 22, 2015 @ 15:07
    aleksandar
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft