Copied to clipboard

Flag this post as spam?

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


  • Nicolai 48 posts 201 karma points
    Sep 18, 2015 @ 08:40
    Nicolai
    0

    How to find all nodes with a specific category from a Multi-Node Tree Picker ?

    Hey guys,

    My homepage is built up with three different categories:

    • Travels
    • Articles
    • Meetings

    All nodes are within one of these categories and now im having trouble finding all nodes with e.g. Travel as the category.

    It is in C# and not XSLT

    Can anyone explain how this is done?

    Appreciate any solution or information about this problem

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 18, 2015 @ 09:25
    Dennis Aaen
    0

    Hi Nicolai,

    I think this can help you.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
    @*
        This snippet lists the items from a Multinode tree picker, using the pickers default settings.
        Content Values stored as xml.
    
        To get it working with any site's data structure, set the selection equal to the property which has the
        multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
    *@
    
    
    @{
        if (Model.Content.HasValue("PropertyWithPicker"))
        {
            var bannerListValue = Model.Content.GetPropertyValue<string>("PropertyWithPicker");
            var bannerList = bannerListValue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var bannerCollection = Umbraco.TypedContent(bannerList).Where(x => x != null);
            foreach (var item in bannerCollection.Where(x => x.DocumentTypeAlias == "umbTextPage"))
            {
                <p>@item.Name</p>
            }
        }
    }
    

    With this code you are getting the items that are picked in the multi-node tree picker on the current page, and then I only pull out the items that uses the umbTextPage document type.

    So what you need to do in the example above to get it working with your setup is to change this "PropertyWithPicker" so it match the alias of your picker.

    After this you will also need to change "umbTextPage" so it match the alias of the category that you want to get.

    Hope this helps,

    /Dennis

  • Nicolai 48 posts 201 karma points
    Sep 18, 2015 @ 09:52
    Nicolai
    0

    What if my categories are not on the current page? They are located at this location in my umbraco folder hierarchy:

    Root/Folder/Categories/category

    I found a solution with XSLT but I would really like to learn how to do this in a partial view.

  • Henrik Vincent 122 posts 616 karma points
    Jul 29, 2016 @ 15:31
    Henrik Vincent
    0

    Did you ever find a solution to this?
    I'm sitting with the same problem

  • Nicolai 48 posts 201 karma points
    Jul 30, 2016 @ 07:57
    Nicolai
    0

    Im afraid not. I went with the XSLT solution.

    If you come up with a solution, please share

Please Sign in or register to post replies

Write your reply to:

Draft