mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-04 19:54:14 +02:00
- bugfix {foreach} item variable must be created also on empty from array https://github.com/smarty-php/smarty/issues/238 and https://github.com/smarty-php/smarty/issues/239
This commit is contained in:
@@ -42,27 +42,23 @@ class Smarty_Internal_Runtime_Foreach
|
||||
settype($from, 'array');
|
||||
}
|
||||
$total = ($needTotal || isset($properties[ 'total' ])) ? $this->count($from) : 1;
|
||||
if (isset($tpl->tpl_vars[ $item ])) {
|
||||
$saveVars[ $item ] = $tpl->tpl_vars[ $item ];
|
||||
}
|
||||
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||
if (empty($from)) {
|
||||
$from = null;
|
||||
$total = 0;
|
||||
if ($needTotal) {
|
||||
if (isset($tpl->tpl_vars[ $item ])) {
|
||||
$saveVars[ $item ] = $tpl->tpl_vars[ $item ];
|
||||
}
|
||||
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||
$tpl->tpl_vars[ $item ]->total = 0;
|
||||
}
|
||||
} else {
|
||||
if (isset($tpl->tpl_vars[ $item ])) {
|
||||
$saveVars[ $item ] = $tpl->tpl_vars[ $item ];
|
||||
}
|
||||
if ($key) {
|
||||
if (isset($tpl->tpl_vars[ $key ])) {
|
||||
$saveVars[ $key ] = $tpl->tpl_vars[ $key ];
|
||||
}
|
||||
$tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||
}
|
||||
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
|
||||
if ($needTotal) {
|
||||
$tpl->tpl_vars[ $item ]->total = $total;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user