Gravatar for thomas.johansson@ifsworld.com

Question by thomasj, Oct 2, 2014 4:46 AM

FacetView in Sitecore Free Edition

Hi, When you add a facet to a search page you can set the title of the facet in PageEditor and the code in the Facet View looks like this by default: div class="CoveoFacet " data-title='@Model.Title' data-field='@Model.Field'….

What we want is actually to use the Facets DisplayName as this can be localized. When I customze the searchresult i can use someting like this: {{= raw.@(Model.ToCoveoFieldName("DisplayName", false))}} but it do not work in the data-title parameter. How can I achive this in the facet view?

2 Replies
Gravatar for lbergeron@coveo.com

Answer by Luc Bergeron, Oct 2, 2014 8:51 AM

Hi Thomas,

I did it this way:

  1. Created a new item based on the "Facet Parameters" template. In my case, it uses the "Template" Sitecore facet.
  2. Set the display name ot this item for different languages.
  3. Using the Page Editor, I added a Facet View component and set its datasource field on the item created previously. Save and reload the page.
  4. Then modified the FacetView.cshtml to set the data-title attribute like this: data-title='@Model.BoundRendering.Item.DisplayName'

Let me know if it works for you

Gravatar for thomas.johansson@ifsworld.com

Comment by thomasj, Oct 2, 2014 10:45 AM

Nice, It worked just fine. Thanks a lot!

Gravatar for lbergeron@coveo.com

Comment by Luc Bergeron, Oct 2, 2014 10:46 AM

Great! You're welcome!

Gravatar for vseguin@coveo.com

Answer by Vincent Séguin, Oct 2, 2014 7:39 AM

Hi Thomas,

Actually it should be {{= raw.@Html.Coveo().ToCoveoFieldName("DisplayName", false)}} instead of just @(Model…)

Let me know if it works!

Gravatar for thomas.johansson@ifsworld.com

Comment by thomasj, Oct 2, 2014 8:28 AM

Hi, Sorry but it did not work. The facet name looks like: {{=raw.fdisplayname98168}} and the code in the view is

div class="CoveoFacet " data-title='{{=raw.@Html.Coveo().ToCoveoFieldName("DisplayName", false)}}' (I have tried without the ' also)

It also says that the 'Coveo.UI.Extensions.CoveoMvcHelper.ToCoveoFieldName(string, bool)' is obsolete: '"Use the Model.ToCoveoFieldName(string, bool) method instead."'

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Oct 2, 2014 8:39 AM

Hi Thomas,

Indeed, my bad, i didn't understand your question correctly. Actually, the 'raw' is used only for search results, to access fields on the results for example. It's not useful for a facet. We'll answer with a working solution in a few minutes.

Ask a question