Coveo Hive and Field Based Suggestions
How can I use Field Based Suggestions in Coveo Hive?
I mean this <span class="CoveoFieldSuggestions" data-field='@(Model.ToCoveoFieldName("Title"))'></span>
`Model.ToCoveoFieldName("Title")` in the Coveo for Sitecore Hive Framework is gone. The way this method was bound to the current context was stopping us from putting the Coveo Search Interface in cache, which should give you a performance boost.
There are two alternatives:
# Prebinding #
A new mechanic in Coveo for Sitecore Hive is to execute methods on fields before a component initialization.
The syntax is the following: `data-prebind-YOURATTRIBUTE="PREBINDING_METHOD"`
The prebinding method that you need is called `fieldTranslator`.
You can then set `data-field="title"` coupled with `data-prebind-field="fieldTranslator"`.
If you check in the markup, after the execution, your field should now look like `data-field="ftitleXXXX"`
This is the recommended method to do simple operations.
Note that I will write a topic about this soon enough in the documentation :)
<span id="myfieldsuggestion" class="CoveoFieldSuggestions"></span>
This code will modify its attribute:
document.getElementById("myfieldsuggestion").dataset.field = CoveoForSitecore.Context.fields.toCoveo("title");
This will give you the same result as the first option. It is a little less friendly, requires a unique ID, but is way more powerful.
So this is the recommended method if you want to build complex objects or expressions.
Hope this helps!