XaminProject / handlebars.php

Handlebars processor for php
331 stars 132 forks source link

How to use @last in #each #152

Closed jcubic closed 8 years ago

jcubic commented 8 years ago

I want to have something like this:

{{#each items}}
{{this}}{{#if !@last}}, {{/if}}
{{/each}}

to display comma after all items except the last one. How can I do this?

JustBlackBird commented 8 years ago

There is built-in {{#unless}} helper that solves your problem:

{{#each items}}
  {{this}}{{#unless @last}}, {{/unless}}
{{/each}}