Why can't I use TransformData on the header or footer?
Like this:
search.addWidget(
instantsearch.widgets.refinementList({
container: '#container',
attributeName: 'Attribute',
sortBy: ['name:asc'],
limit: 10,
operator: 'and',
transformData: function(data){
data.myValue = "some new value";
},
templates: {
header: "{{myValue}}"
}
})
);
@Giovanni-Mattucci I think you need to use:
transformData: {
header: function() {
}
}
Let me know how it goes
I tried that and it didn't seem to work.
search.addWidget(
instantsearch.widgets.refinementList({
...
transformData: {
header: function(data) {
/*never actually runs?*/
return data.myValue = "some new value";
console.log('I am never reached'); //never gets run
}
}
templates: {
header: "{{myValue}}"
}
})
);
Ok so then no that's not feasible, what you can do is pass a function to the header template instead of a string, then return a string of text (not a mustache template).
Would that be ok for you?
@vvo yes what you suggested is the way to go.
search.addWidget(
instantsearch.widgets.refinementList({
...
templates: {
header: function(){
var myValue = someOtherData;
return "some new value" + myValue
}
}
})
);
Being able to TransformData Header and Footer templates would be useful in this case, as only item is supported: https://community.algolia.com/instantsearch.js/v2/widgets/refinementList.html#struct-RefinementListTransforms
Thanks for closing this old issue @Giovanni-Mattucci 鉂わ笍