mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 08:44:12 +03:00
Merge pull request #26 from boukeversteegh/master
Added support for @index in #each-helper when used on lists.
This commit is contained in:
commit
05ab5b9cff
@ -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