template render a list of items with HTML #998
-
I have a template that has an array of items I want to list out as
This doesn't work. Does anyone know how to loop through and display the template literal? |
Beta Was this translation helpful? Give feedback.
Answered by
sarahdayan
Jul 1, 2022
Replies: 1 comment 1 reply
-
Hey @akeni, This documentation section explains how to deal with loops when using import { autocomplete } from '@algolia/autocomplete-js';
autocomplete({
// ...
getSources() {
return [
{
// ...
templates: {
item({ item, html }) {
return html`<div>
<img src="${item.image}" alt="${item.name}" />
<div>${item.name}</div>
<ul>
${item.categories.map(
(category) =>
html`<li key="${category.id}">${category.label}</li>`
)}
</ul>
</div>`;
},
},
},
];
},
}); If you can't make it work, please provide a working CodeSandbox so we can reproduce the problem and help you troubleshoot. Here's a starter sandbox using |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
akeni
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @akeni,
This documentation section explains how to deal with loops when using
html
.If you can't make …