Skip to content

Commit

Permalink
- bugfix in nested {foreach} saved item attributes got overwritten #33
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed May 12, 2015
1 parent e4741e9 commit 07c781d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
 ===== 3.1.24.dev ===== (xx.xx.2015)
- bugfix {$smarty.constant.TEST} did fail on undefined constant https://github.com/smarty-php/smarty/issues/28
- bugfix access to undefined config variable like {#undef#} did fail https://github.com/smarty-php/smarty/issues/29
- bugfix in nested {foreach} saved item attributes got overwritten https://github.com/smarty-php/smarty/issues/33

===== 3.1.23 ===== (12.05.2015)
12.05.2015
Expand Down
2 changes: 1 addition & 1 deletion libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.24-dev/1';
const SMARTY_VERSION = '3.1.24-dev/2';

/**
* define variable scopes
Expand Down
9 changes: 6 additions & 3 deletions libs/sysplugins/smarty_internal_compile_foreach.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public function compile($args, $compiler, $parameter)
}
}
}
$output .= "\$foreachItemSav = \$_smarty_tpl->tpl_vars[$item];\n";
$itemName = trim($item,"'\"");
$output .= "\$foreach_{$itemName}_Sav = \$_smarty_tpl->tpl_vars[$item];\n";
$output .= "?>";

return $output;
Expand Down Expand Up @@ -239,8 +240,9 @@ public function compile($args, $compiler, $parameter)

list($openTag, $nocache, $item, $key, $foo) = $this->closeTag($compiler, array('foreach'));
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $item, $key, false));
$itemName = trim($item,"'\"");
$output = "<?php\n";
$output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreachItemSav;\n";
$output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n";
$output .= "}\n";
$output .= "if (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
return $output;
Expand Down Expand Up @@ -274,9 +276,10 @@ public function compile($args, $compiler, $parameter)
}

list($openTag, $compiler->nocache, $item, $key, $restore) = $this->closeTag($compiler, array('foreach', 'foreachelse'));
$itemName = trim($item,"'\"");
$output = "<?php\n";
if ($restore) {
$output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreachItemSav;\n";
$output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n";
}
$output .= "}\n?>";

Expand Down

0 comments on commit 07c781d

Please sign in to comment.