Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dynamic array items #1735

Closed
roipoussiere opened this issue Feb 10, 2021 · 2 comments
Closed

Allow dynamic array items #1735

roipoussiere opened this issue Feb 10, 2021 · 2 comments

Comments

@roipoussiere
Copy link

roipoussiere commented Feb 10, 2021

It is possible to retrieve the third array element with items.[2], but it seems not possible to do the same thing with a dynamic value, for instance items.[@index].

It could be interesting to loop over several arrays at the same time, such as:

// data = {numbers: ['zero', 'one', 'two'], values: ['foo', 'bar', 'baz']}
<ul>{{#each values}}<li> {{.}}: {{@index}} -> {{@root.numbers.[@index]}}</li>{{/each}}</ul>

Test code: https://jsfiddle.net/t9njfw5v/1/

It can be achieved with this helper:

Handlebars.registerHelper('get', function(array, i) {return array[i]});

but it's less practical.

@peepo5
Copy link

peepo5 commented Jan 16, 2023

why is this not a thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants