- Feature specific data from within your records to, for example, show promotional prices during a sales period
- Display advertisements or promotional banners.
To learn how to suppress InstantSearch’s initial ,
see Conditional requests.
Handle searches without results
When a query doesn’t return results, display a message and suggest changing the query or clearing filters.Display a message
To display a fallback message when a query doesn’t return results, use thetemplates.empty option.
All examples in this guide assume you’ve included InstantSearch.js in your web page from a CDN.
If, instead, you’re using it with a package manager, adjust how you import InstantSearch.js and its widgets for more information.
JavaScript
The preceding example also works with
infiniteHits.Let users reset filters and facets
If users apply an overly specific configuration, they may not find any results. Account for this by letting them reset filters from the “no results” display so they can start another search. Do this with theclearRefinements widget.
However, you can’t use it inside the empty template, so must use routing instead.
First, activate the URL sync mechanism:
JavaScript
JavaScript
Handle empty queries
By default, InstantSearch sends search requests even when the query is empty. To hide results until users enter a query, use the following code. This hides the results without preventing search requests.Using transformItems
Using transformItems to display no results when the query is empty:
JavaScript
Using a connector
The following example uses theconnectHits connector.
JavaScript
Handle search errors
If an error occurs, you can display a specific piece of content to help users return to the standard state.Making an error-handling widget
You can build a custom widget to handle errors. If you want to learn more about custom widgets, check out the guide.JavaScript