Step 5: Customizing Result Templates
Step 5: Customizing Result Templates
Now that you have a search page with some basic controls, you’re ready to customize the result templates.
Result templates dictate the way that search results are displayed in your search interface. Since you don’t currently have any templates, the Coveo JavaScript Search Framework simply displays the document Title field, as well as an excerpt when the HTML was crawled at indexing time.
Coveo for Sitecore Hive provides a Default Template which you can use for a richer result list. You can find this template on the website root folder under Coveo > Hive > Templates.
Result templates leverage the Underscore library and are highly extensible.
We recommend that you create a new file instead of changing the default one when creating or modifying a result template.
For this tutorial, you’ll assign the Default template to your results.
-
In the Sitecore Experience Editor for your search page, select the result-template placeholder. It should be just above your result list.
-
Select Add here, and select the Coveo File Result Template.
-
In the Select the Associated Content window, select Create New Component and choose the parent you prefer.
-
Save your page. You should see the following error:
Undefined Result Template. Please configure the component.
-
Click the error message, bringing you to the Coveo File Result Template controller.
-
Open its properties by clicking the Coveo icon on the left.
-
In the properties window, under Basic Settings > File Template Name, enter
default
. -
Select OK to save and close the properties window, and click the Save icon to save your page.
-
Your Result Template control should show a warning since the file has not yet been specified. To solve this:
-
Click the Result Template control and open its properties by clicking the Coveo button.
-
Look for the File Template Name and type
default
in the input. -
Close the properties and save the page.
-
Your result list should now use your result templates.
You can add many templates in a single Result List to show different results based on different items.
You should now proceed to Step 6: Changing the Result Layout.