I found a solution. Jesse's solution would work but would mean that as the data is manipulated it would need to be pulled in and out of the array (inefficient and a hassle).
Instead we can do something with index.
Here is an example:
$h = new Handlebars\Handlebars;
echo $h->render(
'{{#each data}}
{{@index}} {{#unless @last}}Not last one!{{/unless}}{{#if @last}}Last entry!{{/if}}
{{/each}}',
array(
'data' => ['a', 'b', 'c']
)
);
echo "\n";
echo $h->render(
'{{#each data}}
{{@index}} {{#if @first}}The first!{{/if}}{{#unless @first}}Not first!{{/unless}}
{{/each}}',
array(
'data' => ['a', 'b', 'c']
)
);
echo "\n";
echo $h->render(
'{{#each data}}
{{@index}} {{#unless @index}}The first!{{/unless}}{{#if @index}}Not first!{{/if}}
{{/each}}',
array(
'data' => ['a', 'b', 'c']
)
);
the output (master) will be:
0 Not last one!
1 Not last one!
2 Last entry!
0 The first!
1 Not first!
2 Not first!
0 The first!
1 Not first!
2 Not first!
which is what you're looking for, right? even the example in wycats/handlebars.js#483, works:
$h = new Handlebars\Handlebars;
echo $h->render(
'
{{#each data}}
{{@index}}
{{#if @last }}
Last entry!
{{/if}}
{{/each}}',
array(
'data' => ['a', 'b', 'c']
)
);
the output:
0
1
2
Last entry!
simply do an #each and then check if @first and then manipulate it as a special case in your loop.
I found my example here: https://github.com/XaminProject/handlebars.php/issues/52