Gravatar for wrolloff@gmail.com

Question by Will Rolloff, Nov 28, 2017 12:06 AM

How to create Coveo Hive custom result templates and set display conditions

I am working with Coveo Hive and generating a ton of custom versions of the Coveo layouts, placeholders, and renderings. I do not quite understand how the new result template renderings work.

With Legacy Coveo for Sitecore, I created partial MVC views and then added conditions to load various underscore templates that mapped to those views. The condition logic was specified in JavaScript to modify what was passed to the loadTemplate() function. How is this done in Coveo Hive? I created a custom rendering based on the "File Result Template". It does not look like it finds the view through the new renderings Path parameter, but rather looks at the data source items "File Template Name" field. The file path is then searched by looking at YOUR_WEBSITE/Coveo/Hive/templates/TEMPLATE_NAME.cshtml. Is this correct? Is there a way to change the default path where this looks for my view files?

Secondly, how do I map the new result template based on a condition where the source is from an external index? For example, I want to use the new result template when the data comes from a specific database connector index.

1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Nov 28, 2017 2:03 PM

Let me take your questions one by one :)

1. I am working with Coveo Hive and generating a ton of custom versions of the Coveo layouts, placeholders, and renderings

Coveo for Sitecore Hive was designed to require less duplication, so I would be curious to know the reason you are duplicating so many of the components :)

2. The condition logic was specified in JavaScript to modify what was passed to the loadTemplate() function. How is this done in Coveo Hive?

Your old method with `loadTemplate()` should still work if this is what you would prefer. We ship with new components, but the Coveo JavaScript Search Framework V2.0 has not removed this functionality.

Like you said, the Coveo Hive way of doing it is by inserting a `File Result Template` component. There is a property on this component that allows you to define field conditions. See this topic for more information: Configuring a New Result Template

3. The file path is then searched by looking at YOUR_WEBSITE/Coveo/Hive/templates/TEMPLATE_NAME.cshtml. Is this correct?

Exactly.

4. Is there a way to change the default path where this looks for my view files?

We plan on supporting multiple folders, but for now, you need to put them in the `templates` folder.

5. Secondly, how do I map the new result template based on a condition where the source is from an external index?

You have to configure your field as an External Field then reference it in your template conditions.

Gravatar for wrolloff@gmail.com

Comment by Will Rolloff, Nov 30, 2017 12:56 AM

Question #1

We had many customizations to the Coveo components in the legacy version that we now need to replicate with the new Hive components. This includes creating new layouts, renderings, placeholders to restrict authors to the new customized renderings, new data models and properties to carry over fields for customized functionality, etc. After reviewing the template condition approach I was able to remove a few templates, but there are still a lot of them.

Question #2

Thank you. I updated to use the template conditions and it works very well!

Question #3

Thank you.

Question #4

Great! Being able to group these alongside the other search views while staying away from Coveo folders would be ideal.

Question #5

Thank you. I am converting all of the rules to use template conditions instead.

Thank you very much for all of your insight @François Lachance-Guillemette!!

Gravatar for pblrok@gmail.com

Comment by pblrok, Nov 30, 2017 8:13 AM

Question #3

You can duplicate ResultTemplate and write property class like current implementation in out of box:

but you shoud replace ResultTemplateNameToPathConverter on your implementation

current ResultTemplateNameToPathConverter looks like that

also you can read this answer coveo-hive-and-a-custom-component

Ask a question