Gravatar for

Question by esavoie, Dec 9, 2015 4:54 PM

Integrating other Sitecore sublayouts on a Search page

We have a search page for our client that is working fine, but we need to be able to add some custom sublayout code on top of the results, if the term they matched is a given term.

For example, if they perform a query, we want to show a featured content section (not a curated result) above the results with some copy, images etc…

Currently, you are not using full querystrings for your parameters, you are using a # instead of a ?. This is because the whole process is Ajax driven and does not make server trips to Sitecore when you update your search term. It would seem that the only way to hook into the search term (#q=) would be through a JS event handler that would make a clientside Ajax request to Sitecore and return some JSON that we could place on the page. Do you possibly have any documentation, how we could hook into a specific JS event that is triggerred when a new search has been requested so that we could do such a process?

1 Reply
Gravatar for

Answer by Simon, Dec 21, 2015 11:57 AM

You can bind yourself to a JS UI event:

Since you are using Coveo for Sitecore, be aware that Sitecore uses it's own jQuery for the Page Editor, so you need to use the Coveo jQuery plugin:

Coveo.$('#search').on('duringQuery', function (e, data) { 
console.log(data); }); 

For more examples of usage in Coveo for Sitecore:

Ask a question