From b525d4d1d7d5990bfa7e1225045301c15f93ff02 Mon Sep 17 00:00:00 2001 From: uwetews Date: Tue, 12 Jul 2016 00:24:11 +0200 Subject: [PATCH] - 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 --- change_log.txt | 3 +++ libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_internal_runtime_foreach.php | 12 ++++-------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/change_log.txt b/change_log.txt index 1870206b..f149ac7b 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.30-dev ===== (xx.xx.xx) + 12.07.2016 + - 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 + 27.05.2016 - bugfix/improvement of compileAlltemplates() follow symlinks in template folder (PHP >= 5.3.1) https://github.com/smarty-php/smarty/issues/224 clear internal cache and expension handler for each template to avoid possible conflicts https://github.com/smarty-php/smarty/issues/231 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index a0f556aa..9f366d9a 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.30-dev/72'; + const SMARTY_VERSION = '3.1.30-dev/73'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_runtime_foreach.php b/libs/sysplugins/smarty_internal_runtime_foreach.php index 6d8737fe..bdefe692 100644 --- a/libs/sysplugins/smarty_internal_runtime_foreach.php +++ b/libs/sysplugins/smarty_internal_runtime_foreach.php @@ -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; }