Copied to clipboard

Flag this post as spam?

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


  • Jesper Skjønnemand 39 posts 274 karma points
    Sep 09, 2019 @ 14:04
    Jesper Skjønnemand
    0

    Which nodes have picked the current node?

    Hola Umbracos

    I have two page types, Store and Service.

    The Store pages contain a multinode treepicker where the managers can select the services that are available in their specific stores. My template generates a nice list of available services. No problem so far.

    Now, on the Service pages I need to generate a list of stores that offer the specific service, i.e. Store pages where the current Service page is selected with the multinode treepicker.

    I could really use some suggestions on how to go about this.

    Best

  • Paul Seal 402 posts 2205 karma points MVP 2x c-trib
    Sep 09, 2019 @ 14:52
    Paul Seal
    0

    Hi Jesper

    I would do an examine query to search for the udi value of the current node. I would make the examine query search the property alias of the multi node tree picker for the udi value from the current node.

    Here is an extension for getting the udi for the current page which is safe to query in examine:

    public static string SafeUdi(this IPublishedContent contentItem, string udiType = "document")
    {
        var udi = new GuidUdi(udiType, contentItem.GetKey());
        return udi.ToString().Replace(":", "\\:");
    }
    

    So build up your examine query and pass in contentItem.SafeUdi() as your search term.

    Something like this:

    var searchTerm = Model.Content.SafeUdi();
    
    var searcher = index.GetSearcher();
    var results = searcher.CreateQuery("content").NodeTypeAlias("store").And().Field("services", searchTerm).Execute();
    

    Here is a link to the examine documentation quick start:

    https://our.umbraco.com/documentation/reference/searching/examine/quick-start/

    Cheers

    Paul

  • Shaishav Karnani from digitallymedia.com 346 posts 1622 karma points
    Sep 09, 2019 @ 14:57
    Shaishav Karnani from digitallymedia.com
    0

    Hi Jesper,

    Paul example is perfect but just thought an alternative simple approach.

    var listStores = CurrentPage.AncestorOrSelf(1).DescendantsOrSelf("store");

    var selectedStores = new List

    foreach (var s in listStores) { if (s.Services.Any(x=>x.Id == CurrentPage.Id)) { selectedStores.Add(s); } }

    Cheers,

    Shaishav

  • Jesper Skjønnemand 39 posts 274 karma points
    Jan 29, 2020 @ 13:43
Please Sign in or register to post replies

Write your reply to:

Draft