Handlebars @last not supported?


#1

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}}

#2

Don’t believe it’s supported. But, if you use https://github.com/jmurphyau/ember-truth-helpers, 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}}

#3

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.