Personnalize Stats Widget

How can I personnalise the widget in order to have :
-“297 products” instead of “297 results found in 7ms”

  search.addWidget(
      instantsearch.widgets.stats({
        container: '#stats-container'
      })
    );

Thanks

Hi there,

You can pass a custom template for this widget in the following way:

search.addWidget(
  instantsearch.widgets.stats({
    containers: '#stats-container',
    templates: {
      body: "{{#hasManyResults}}- {{nbHits}} products{{/hasManyResults}}{{#hasOneResult}}- 1 product{{/hasOneResult}}{{#hasNoResults}}- No products matched the search query{{/hasNoResults}}"
    }
  })
);

You can find more informations about the stats widget here:

Thanks but I got this issue :

stats.js:50 Uncaught Error: Usage:
stats({
  container,
  [ templates.{header,body,footer} ],
  [ transformData.{body} ],
  [ autoHideContainer]
})

Hi There,

I think you got a syntax error somewhere. To make things easier, I wrote an example here:

https://codepen.io/proudlygeek/pen/xLgQyM

Try to type something and you should see the stats widget updating accordingly:

Let me know if this helps you out.

1 Like

Thanks it helps me a lot.

1 Like