0

Hi I have made a instant search with images but I want them to click the image and redirect them to a different page. I have been searching for ages and I'm so stuck. what do I need to add in the index and how to add it in javascript.

I use json for the indexes.

add href to a image. I use javascript and html.

visual
  • 1

1 Answers1

0

In the index, you need to have one attribute for the url of the link and one attribute for the src of the image.

var myRecord = {
    url: "/this-cat.html",
    image: "/cat-pic.png",
    ... // other attributes
}

Then, you need to use both in the template:

templates: {
    item: '<a href="{{{url}}}"><img src="{{{image}}}" /></a>'
}

Here's a template that does this from the instantsearch e-commerce example.

Josh Dzielak
  • 1,803
  • 17
  • 19