I am getting a compilation error in ember-cli whenever I have a Handelbars template that uses @vars variables (i.e., @index, @key, @first, @last) inside of the each helper.
That really isn't related to ember-cli. Ember Handlebars doesn't support the @keyword items.
It's possible to mimic behavior of following Handlebars keywords: @index
, @key
, @first
, @last
.
{{#each array as |item index|}}
Index of item: `{{item}}` is: `{{index}}`
{{/each}}
{{#each-in object as |key value|}}
{{key}}: {{value}}
{{/each-in}}
You could also mimic behavior of @first
using ember-truth-helpers addon and taking advantage of eq
helper - thanks to kristjan reinhold for this idea:
{{#each array as |item index|}}
{{#if (eq index 0)}}
<!-- first element specific html -->
{{else}}
<!-- other html -->
{{/if}}
{{/each}}
Instead of (eq index 0)
you can use (eq item array.firstObject)
.
As dwickern suggested you can use Ember.Array.lastObject to mimic @last behavior.
{{#each array as |item|}}
{{#if (eq item array.lastObject)}}
<!-- last element specific html -->
{{else}}
<!-- other html -->
{{/if}}
{{/each}}