Render computed index field value in Coveo Hive search result template

There may come a time when you need to render the value of a custom field you created in the search results of your Coveo Hive search interface. Specifically, you would want to edit the search result template – hopefully you created a new one based on the file provided out of the box. How do you make the value appear though? I found this to be much more involved than I expected.

The isExternal setting

When it comes to rendering the value of the custom field, one setting is very important. In the fieldMap where you defined your custom field, you can choose whether you wish the field to be treated like a Coveo for Sitecore field (and to consequently appear in the content browser in a format such as fmyfield99999), or to be treated as an external (non-Sitecore) field, but still work with Coveo (and thus, appear without any characters added, like myfield). The setting you need to add or check: isExternal. Example:

 <fieldType fieldName="resultDate" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" isExternal="true" />

The underscore code required will depend on whether the value of that setting is true or false (false being the default). Whether you use {{ }} or <% %> syntax is up to you.

Coveo for Sitecore Fields

If the setting is false or not supplied, your field is a Coveo for Sitecore field, and could be rendered in one of the following ways:

1. Using the coveoFieldValue helper.

{{- coveoFieldValue("myfield") }}

2. Using the coveoFieldName helper in a div (WordPress didn’t like HTML in my blog post so I had to strip out the tag syntax):

div class="CoveoFieldValue" data-field="{{- coveoFieldName("contentType")}}" /div

If these don’t work, try adding @@ before the field name.

External Fields

If you provide the isExternal setting with a value of true, you can render the value of it using raw.

{{- raw.myfield }}

Using the coveoFieldName helper in a div also works.

Note that when using raw, the name of your field needs to be all lowercase, or the value will not be rendered. I was confused by this, because I entered my field name in the Coveo.SearchProvider.Custom.config as myField. Coveo support answered:

All the fields are actually translated to the index’s format, restricted to only lowercase letters, numbers and underscores:

During the indexing process, any field name that do not meet those requirements will be translated to that format (Coveo for Sitecore fields also get a unique hash added so that they are unique to each index).


You should be able to use the image() and date() helpers just fine now that you are using the correct syntax. Just note that if your field is external and you are using raw, your field name must be in lowercase. From what I can see, it doesn’t need to be all lowercase if you are using the other helpers. Hope this helps!

2 thoughts on “Render computed index field value in Coveo Hive search result template

  1. I am using coveo for sitecore and wanted to render the image in the search result page. i dont want to do any config changes. Is there any way to render the image through result template. The indexed image is in this format:
    But to render the image in correct format I would like to convert it in this format :

    I am new to underscore js and sitecore and tried using split and other methods but not able to achieve this.Any help on this is highly appreciated.


    1. Hi Nikietaa, I think some information is missing from your comment. If it’s HTML, WordPress will automatically remove it.

      It’s been a while since I’ve done Coveo stuff, but I might be able to take a stab at it once you provide the missing information. Thanks!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s