mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 08:44:12 +03:00
Added support for @index in #each-helper when used on lists.
This commit is contained in:
parent
c441a93a9f
commit
eda8d34cbb
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user