- bugfix using a {foreach} property like @iteration could fail when used in inheritance parent templates (Issue 182)

This commit is contained in:
Uwe.Tews@googlemail.com
2014-03-24 18:52:29 +00:00
parent 478db521c9
commit 474e863af1
2 changed files with 15 additions and 13 deletions

View File

@@ -1,4 +1,7 @@
===== trunk ===== ===== trunk =====
24.03.2014
- bugfix using a {foreach} property like @iteration could fail when used in inheritance parent templates (Issue 182)
20.03.2014 20.03.2014
- bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899) - bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899)

View File

@@ -49,7 +49,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, $compiler, $parameter)
{ {
$tpl = $compiler->template;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -80,12 +79,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
$ItemVarName = '$' . trim($item, '\'"') . '@'; $ItemVarName = '$' . trim($item, '\'"') . '@';
// evaluates which Smarty variables and properties have to be computed // evaluates which Smarty variables and properties have to be computed
if ($has_name) { if ($has_name) {
$usesSmartyFirst = strpos($tpl->source->content, $SmartyVarName . 'first') !== false; $usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false;
$usesSmartyLast = strpos($tpl->source->content, $SmartyVarName . 'last') !== false; $usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false;
$usesSmartyIndex = strpos($tpl->source->content, $SmartyVarName . 'index') !== false; $usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false;
$usesSmartyIteration = strpos($tpl->source->content, $SmartyVarName . 'iteration') !== false; $usesSmartyIteration = strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false;
$usesSmartyShow = strpos($tpl->source->content, $SmartyVarName . 'show') !== false; $usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false;
$usesSmartyTotal = strpos($tpl->source->content, $SmartyVarName . 'total') !== false; $usesSmartyTotal = strpos($compiler->lex->data, $SmartyVarName . 'total') !== false;
} else { } else {
$usesSmartyFirst = false; $usesSmartyFirst = false;
$usesSmartyLast = false; $usesSmartyLast = false;
@@ -93,12 +92,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
$usesSmartyShow = false; $usesSmartyShow = false;
} }
$usesPropFirst = $usesSmartyFirst || strpos($tpl->source->content, $ItemVarName . 'first') !== false; $usesPropFirst = $usesSmartyFirst || strpos($compiler->lex->data, $ItemVarName . 'first') !== false;
$usesPropLast = $usesSmartyLast || strpos($tpl->source->content, $ItemVarName . 'last') !== false; $usesPropLast = $usesSmartyLast || strpos($compiler->lex->data, $ItemVarName . 'last') !== false;
$usesPropIndex = $usesPropFirst || strpos($tpl->source->content, $ItemVarName . 'index') !== false; $usesPropIndex = $usesPropFirst || strpos($compiler->lex->data, $ItemVarName . 'index') !== false;
$usesPropIteration = $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'iteration') !== false; $usesPropIteration = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false;
$usesPropShow = strpos($tpl->source->content, $ItemVarName . 'show') !== false; $usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false;
$usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'total') !== false; $usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false;
// generate output code // generate output code
$output = "<?php "; $output = "<?php ";
$output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable; \$_smarty_tpl->tpl_vars[$item]->_loop = false;\n"; $output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable; \$_smarty_tpl->tpl_vars[$item]->_loop = false;\n";