2

Using sitecore 8 (8.2 update 3 to be specific)

I'm looking to be able to create a rule based on some condition which will set the datasource (and maybe rendering) to the most appropriate result from a search result given a users context.

Personalising a rendering only allows you to pick a datasource (and rendering) to a fixed item by id. But I'm looking for a dynamic result based on the results of a query.

When searching the nearest I can find is https://adeneys.wordpress.com/2011/04/28/decoupling-through-the-rules-engine/ Which allows for performing a sitecore query to select the datasource. But this is for an older version of sitecore, and now in v8 when Personalising a rendering you have a limited set of actions (hide, change rendering, change datasource)

I also found an article on building up a search query in sitecore via rule queries https://cardinalcore.co.uk/2014/07/23/rules-queries-pt-iii-what-can-we-use-rules-queries-for/ And at the end mentions future posts about extending rule queries for conditions and actions, but I can't find the follow up posts.

Any idea of if what I'm trying to achieve is possible, and what I need to extend to make this possible in sitecore 8.

4
  • Can you give an example of a user, their aims and what you want to show based on this. e.g 'Given I am user a (who wants to see/do xyz) I should set the datasource to abc' ? this will help suggest options available to you. Commented Aug 2, 2017 at 10:30
  • As an example users browsing from different countries, should get a different rendering/datasource based on a search to find the most relevant content for them. (content will be tagged)
    – Ian
    Commented Aug 2, 2017 at 11:09
  • Sitecore support have pointed me at the resolveRenderingDatasource pipeline. Evaluating is that meets my needs. Looks like should be able to point the data source at a search definition item, and resolve the data source in the pipeline before getting to the rendering. Still looking for if there is an equivalent for the swapping of the rendering.
    – Ian
    Commented Aug 2, 2017 at 12:06
  • Hmmm, maybe you could instead power your component from search (solr) instead of from a data source and then you can populate it with whatever you want based on the page/user context? Commented Aug 2, 2017 at 16:42

1 Answer 1

1

One way to do this is to use a controller rendering. On the personalization tab, you can define your conditions and action. Instead of picking a content in the action, you can choose an item that will contain parameters for your query in the index.

enter image description here

Here the UK users contains parameters such as Country, Content Type, Total Count, Sort By.

enter image description here

Then in your controller, you will need to retrieve these values. The item UK users will be passed as a datasource to the controller.

    public class BlockAggregatorController : SitecoreController
{
    public ActionResult RenderBox()
    {
        var currentDatasource = Datasource;

        var totalCount= currentDatasource.Fields["Total Count"].Value;
        //get the other values you need to do the index query


    }


    private Item Datasource
    {
        get
        {
            var dataSourceId = RenderingContext.Current.Rendering.DataSource;
            return ID.IsID(dataSourceId) ? Context.Database.GetItem(dataSourceId) : null;
        }
    }

}

This is what your controller rendering will be like.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.