Added support for @index in #each-helper when used on lists.

This commit is contained in:
Bouke Versteegh 2013-11-01 18:27:13 +01:00
parent c441a93a9f
commit eda8d34cbb

View File

@ -104,12 +104,22 @@ class Handlebars_Helpers
$tmp = $context->get($args);
$buffer = '';
if (is_array($tmp) || $tmp instanceof Traversable) {
$islist = ( array_keys($tmp) == range(0, count($tmp) - 1) );
foreach ($tmp as $key => $var) {
$context->pushKey($key);
if( $islist ) {
$context->pushIndex($key);
} else {
$context->pushKey($key);
}
$context->push($var);
$buffer .= $template->render($context);
$context->pop();
$context->popKey();
if( $islist ) {
$context->popIndex();
} else {
$context->popKey();
}
}
}
return $buffer;