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 31 posts 255 karma points
    6 days ago
    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 376 posts 2047 karma points MVP 2x c-trib
    6 days ago
    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 257 posts 1119 karma points
    6 days ago
    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

Please Sign in or register to post replies

Write your reply to:

Draft