Getting results count and show in header

Hi guys,

I’m trying to do something simple, but unfortunately I don’t get it.
I’m using the autocomplete JS (WordPress) and would like to show a count of results for my specific index.
The Autocomplete searches in multiple indexes and shows the limited (max_suggestions) suggestions. I would like to show the total amount of results found.

I’m trying to do the following:

{{{ data.label }}} ({{{ data.suggestions }}})

But unfortunately data doesn’t have the suggestions parameter or something like this.

Any suggestions?

Thanks,
Justin

Hey Justin,

As demoed by @vvo here, it’s possible to do it roughly like this:

templates: {
  header: function(data, algoliaResponse) {
    return `Nb hits: ${algoliaResponse.nbHits}`;
  },
}

See the demo

1 Like