I was trying to handle some special logic for the last item in an array and was trying to therefore use the handlebars @last helper. However, it seems the @last helper is never even set. At least it does not seem to evaluate if I try to directly print it’s value and my logic does not work. May it probably be that it is not supported in ember?
{{#each model.replies as |reply|}}
{{#if @last}}
<button {{action 'deleteReply' reply}}>x</button>
{{/if}}
<div>{{reply.msg}}</div>
{{/each}}
Don’t believe it’s supported. But, if you use GitHub - jmurphyau/ember-truth-helpers: Ember HTMLBars Helpers for {{if}} & {{unless}}: not, and, or, eq & is-array, you could do something similar by doing:
{{#each model.replies as |reply|}}
{{#if (eq reply model.replies.lastObject)}}
<button {{action 'deleteReply' reply}}>x</button>
{{/if}}
<div>{{reply.msg}}</div>
{{/each}}
5 Likes
Ah perfect. I did not know about the lastObject helper from the array. I was already having an is-equal helper in my project, so that works nicely without adding anything.
The thing that has been puzzling to me is that the ember documentation states:
Ember templates use the syntax of Handlebars templates. Anything that is valid Handlebars syntax is valid Ember syntax.
So, to me it has not been clear if that includes the built in handlebars helpers or not.
1 Like