Skip to main content

Hit preview

What you're building: a small set of example results shown next to a category, so people can see what is behind a link before clicking it.

Most useful in a mega-menu or a landing page, where hovering "Trainers" shows three trainers rather than just a count.

What you need

  • Applies toA Div for the preview

    Marks the preview region.

  • Applies toThe preview

    Which index to sample from.

  • Applies toThe preview

    Which facet scopes the sample.

  • Applies toThe preview

    Which value of that facet.

All four are required. A preview needs to know what to sample and how to scope it, and there is no wrapper to inherit from.

Build it

<div
wf-algolia-element="hit-preview"
wf-algolia-index="products"
wf-algolia-field="category"
wf-algolia-value="Trainers"
wf-algolia-hits-per-preview="3"
>
<!-- one card, cloned per hit -->
</div>

Inside, design one card and bind fields exactly as in a result template.

How many

sets the sample size. Three or four is usually right — a preview is a taste, and each one is a query.

builds each card's destination, with record fields substituted in:

wf-algolia-hit-link-template="/product/{slug}"
Each preview is its own query

Ten previews in one mega-menu means ten queries on page load. Keep the count small, and prefer previews on hover-revealed panels over rendering every category at once.

Troubleshooting

SymptomCauseFix
Nothing rendersOne of the four required attributes is missingAll four are needed
Cards render emptyField names do not match the recordsCheck them in Algolia
Links all point at the same placewf-algolia-hit-link-template has no field tokenInclude {slug} or similar
The page is slow to loadToo many previews querying at onceReduce them, or defer to hover