Gravatar for nicolas.a.slavik@accenture.com

Question by yonico, Jan 20, 2015 9:59 AM

Coveo resut template customization

Hi - I am trying to use this html code in coveosearch.ascx for cutomizing the result template but get errors in the process.

<% for (int i = 0; i < this.BazaarVoiceRating; i++) {%> <% } for (int j = this.BazaarVoiceRating; j < 5; j++) {%> <% } %>

We would need to replace this.BazaarVoiceRating with {{= raw['<%= ToCoveoFieldName("BazaarVoiceRating", false) %>'] }} but get syntax errors. What it would be the correct way to use it with the coveofieldname?

2 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jan 20, 2015 10:37 AM

This should work or be pretty close to:

{{
  for (var i = 0; i < parseInt(raw['<%= ToCoveoFieldName("BazaarVoiceRating", false) %>']); i++) {
}}
  HTML goes here
{{
  }
  for (var j = parseInt(raw['<%= ToCoveoFieldName("BazaarVoiceRating", false) %>']); j < 5; j++) {
}}
  HTML goes here
{{
  }
}}
Gravatar for nicolas.a.slavik@accenture.com

Comment by yonico, Jan 20, 2015 1:51 PM

thanks - that example works perfectly

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jan 20, 2015 2:49 PM

Please accept this answer as the correct one.

Gravatar for vseguin@coveo.com

Answer by Vincent Séguin, Jan 20, 2015 10:02 AM

Hi,

You can find examples there : https://developers.coveo.com/display/SC201501/Displaying+Results+Differently+According+to+the+Item's+Template and https://developers.coveo.com/display/SC201501/Changing+the+Default+Result+Template.

You need to make sure there's no <% %> tags except the ones needed for the ToCoveoFieldName, since it messes up with the ASP.NET tags. Uses the {{ }} tags everywhere.

Ask a question