Rendering Parameter Template Source Query not working for Droplink.

I have a Sitecore.NET 8.1 (rev. 151207) solution in which I have written a query for getting a specific nodes by template within the current site:

query:./ancestor-or-self::*[@@templatename = 'Root Page']//*[@@templatename = 'Specific Page']

This works for drop links when I set it in the source for standard data templates. But when using the exact same query is used as source for Rendering Parameter Templates drop links, the drop down is not populated. It only works when I specify the exact path or Sitecore ID, but this is no good for a multi site solution.

Is there something special needed to get query working for fields in Rendering Parameter Templates?

  • Hi,

    The reason it is not working is because when the Properties window open, it does not have the item ID of the item that has been selected. For example, opening the presentation details of Item A and click on a sublayout. You will see in the inspect element that the properties window does not have the item id which means at this point it does not know which item it is.

    We had the same issue for our project where we need to make box sizes dynamic per program. What I have implemented is to override the Sitecore Layout details, use a cookie to store the Item ID then retrieve it on the Properties window. Moreover, we had to create a custom token, which then onLoad populates the droplink

    Thanks

  • In reply to Hishaam Namooya:

    Thanks for your contribution. You were right, it was the resolution of the item ID that was causing the problem, but I wasn't keen on using session based persistence as it may cause problems if our editors have multiple tabs open.

     

    I found read a blog written by Przemek Taront on reducing multsite chaos (http://www.cognifide.com/our-blogs/sitecore/reduce-multisite-chaos-with-sitecore-queries/). As the current context was available, even though it wasn't used, it made it easy to create my own pipleline:

    public void Process(GetLookupSourceItemsArgs args)

    {

       if (args == null)

       throw new ArgumentNullException(nameof(args));

       if (!args.Source.StartsWith("query:"))

       return;

       var url = WebUtil.GetQueryString();

       if (string.IsNullOrWhiteSpace(url) || !url.Contains("hdl")) return;

       var parameters = FieldEditorOptions.Parse(new UrlString(url)).Parameters;

       var currentItemId = parameters["contentitem"];

       if (string.IsNullOrEmpty(currentItemId)) return;

       var contentItemUri = new Sitecore.Data.ItemUri(currentItemId);

       args.Item = Sitecore.Data.Database.GetItem(contentItemUri);

    }

     

    And in the config:

    <processor patch:before="*[@type='Sitecore.Pipelines.GetLookupSourceItems.ProcessQuerySource, Sitecore.Kernel']"

    type="MyType, MyAssemblyName" />

     

  • In reply to Colin Bailey:

    Using the code provided, you have been able to retrieve the item from the Properties Window, right?

    Thanks
  • In reply to Hishaam Namooya:

    Correct, the ProcessQuerySource pipeline is fired on opening the property window. From here we get the page Item from the URL parameters and set it against the argument. This results in the Rendering Parameter Templates source query resolving against the current page.
  • In reply to Colin Bailey:

    Thanks for the info. I will try to update mine with your suggestion:)

    Thanks
  • In reply to Colin Bailey:

    Thanks for the post. Answer works just fine in Sitecore 9 as well. Just wanted to make sure people know which pipeline to patch into for Sitecore 9, as I'm not sure if it's different in XP 8. 

    <getLookupSourceItems>
            <processor type="Type, AssemblyName" patch:before="*[@type='Sitecore.Pipelines.GetLookupSourceItems.ProcessQuerySource, Sitecore.Kernel']"/>
          </getLookupSourceItems>