Merge pull request #26 from boukeversteegh/master

Added support for @index in #each-helper when used on lists.
This commit is contained in:
Behrooz Shabani 2013-11-01 10:46:59 -07:00
commit 05ab5b9cff

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;