From 79a4fdcd52d7785dd543371d595853da8a73f743 Mon Sep 17 00:00:00 2001 From: uwetews Date: Mon, 18 Jul 2016 05:27:46 +0200 Subject: [PATCH] - bugfix {foreach} if key variable and item@key attribute have been used both the key variable was not updated https://github.com/smarty-php/smarty/issues/254 --- change_log.txt | 3 +++ libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_internal_compile_foreach.php | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/change_log.txt b/change_log.txt index 8f8d20a2..7acbd5ea 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.30-dev ===== (xx.xx.xx) + 18.07.2016 + - bugfix {foreach} if key variable and item@key attribute have been used both the key variable was not updated https://github.com/smarty-php/smarty/issues/254 + 14.07.2016 - bugfix wrong parameter on compileAllTemplates() and compileAllConfig() https://github.com/smarty-php/smarty/issues/231 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 9725cab5..a65eb4dd 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/80'; + const SMARTY_VERSION = '3.1.30-dev/81'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index 92359618..56d760cd 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -176,11 +176,11 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo $itemAttr[ 'total' ] = true; } $keyTerm = ''; + if (isset($attributes[ 'key' ])) { + $keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => "; + } if (isset($itemAttr[ 'key' ])) { $keyTerm = "{$itemVar}->key => "; - unset($itemAttr[ 'key' ]); - } elseif (isset($attributes[ 'key' ])) { - $keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => "; } if ($this->isNamed) { $foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']";