mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-02 18:26:40 +03:00
Added support for @index in #each-helper when used on lists.
This commit is contained in:
parent
c441a93a9f
commit
eda8d34cbb
@ -104,14 +104,24 @@ class Handlebars_Helpers
|
|||||||
$tmp = $context->get($args);
|
$tmp = $context->get($args);
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
if (is_array($tmp) || $tmp instanceof Traversable) {
|
if (is_array($tmp) || $tmp instanceof Traversable) {
|
||||||
|
$islist = ( array_keys($tmp) == range(0, count($tmp) - 1) );
|
||||||
|
|
||||||
foreach ($tmp as $key => $var) {
|
foreach ($tmp as $key => $var) {
|
||||||
|
if( $islist ) {
|
||||||
|
$context->pushIndex($key);
|
||||||
|
} else {
|
||||||
$context->pushKey($key);
|
$context->pushKey($key);
|
||||||
|
}
|
||||||
$context->push($var);
|
$context->push($var);
|
||||||
$buffer .= $template->render($context);
|
$buffer .= $template->render($context);
|
||||||
$context->pop();
|
$context->pop();
|
||||||
|
if( $islist ) {
|
||||||
|
$context->popIndex();
|
||||||
|
} else {
|
||||||
$context->popKey();
|
$context->popKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user