algolia

Highlighting rendering as text


I have turned on highlighting in the Algolia admin console, and the terms in my search results are getting wrapped with "" and "", but they are showing up as plain text instead of being rendered as HTML. In other words if I search for "test" I see all instances of the word "test" wrapped in the tags instead of being rendered according to that tag's style.

My code to render the results is as follows:

search.addWidget(
    instantsearch.widgets.hits({
         container: '#hits-container',
         templates: {
           empty: 'No results',
           item: '<strong><a href="{{url}}" target="_blank">{{title}}</a></strong><br>{{type}}<br><i><span style="font-size: smaller !important;"{{_highlightResult.summary.value}}</span></i><br>'
         },
         hitsPerPage: 25
    })
);

I feel like I'm overlooking something obvious.

Also - where can I find a reference to all of the possible variables I can use in the template code? I'm not sure I understand the difference between those with two brackets vs those with three brackets.


Solution

  • The highlighted result is stored in the _highlightResult attribute. So instead of {{title}}, you can use {{{_highlightResult.title.value}}} and you will have the highlighted HTML value