Loop through index attribute

I’m trying to figure out how I can loop over an array of values in an attribute in my index. I’ve found this Looping though an index in template?, but I don’t see how it applies since the syntax is incompatible with current algolia specs. Currently hits are being resolved by ${hit.attribute}, while the article is suggesting I use {{#foo}}{{/foo}} which is simply being shown as plain text if I use it in my template.

Am I doing it wrong or is there a new syntax that can be used?

My index is something like this:

{
make: “Toyota”
model: “Camry”
features: [
“Bluetooth”,
“Navigation”,
“Sunroof”
]
}

What I’m trying to do is loop over features and render them in html, how can this be done?

Hi @access,

Welcome to the Algolia Community!

How you loop through your index will depend on the integration or instantsearch you are using.

Could you provide a codesandbox that demonstrates you issue with one of our starter templates?

If you can’t provide codesandbox, could you provide a code snippet of the code you are having issues with?

I look forward to your reply!

Cindy,

I don’t understand what you’re asking. I’ve implemented my code as dictated by algolia documentation, so my template call looks like so:

search.addWidget(
    instantsearch.widgets.hits({
        container: '#grid_results',
        templates: {
            empty: "No results found.",
            item(hit) {
                return hitGridTemplate(hit);
            }
        }
    })
);

and a snippet of that function looks like so:

function hitGridTemplate(hit) {
    /*var features = `${hit.features}`;

return `





{hit.category} {hit.year}
` }

When I try to employ {{#item}}{{/item}} syntax it gets rendered as plain text.

Hi @access

Can you please share your code in a sandbox with minimum code needed to reproduce your issue?

We have starter sandboxes here for all the frontend libraries, with the boilerplate finished: https://github.com/algolia/create-instantsearch-app#previews

This will allow us to see your issue and know better if we can help you resolve it. Thank you!