Skip to content

Use hash keys instead of `as` in {{#each}}

Choose a tag to compare

@phillipskevin phillipskevin released this 05 Oct 21:43
· 748 commits to master since this release

#320

You can now use a hash expression for creating variables localized to an {{#each}} loop.

You can use this when using {{#each}} to iterate over arrays to access the index and value for each item in the array:

{{#each todos todo=value num=index}}
    <li>Todo {{num}}: {{todo.name}}</li>
{{/each}}

You can also use this to access the key and value for each item when iterating over an object:

{{#each person propValue=value prop=key}}" +
    <span>{{prop}}: {{propValue}}</span>
{{/each}}

This also deprecates the {{#each EXPRESSION as KEY}} syntax.