Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/506 foreachelse on arrayiterators #566

Merged
merged 2 commits into from Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_log.txt
@@ -1,3 +1,5 @@
- fix foreachelse on arrayiterators https://github.com/smarty-php/smarty/issues/506

===== 3.1.34 release ===== 05.11.2019
13.01.2020
- fix typo in exception message (JercSi)
Expand Down
10 changes: 4 additions & 6 deletions libs/sysplugins/smarty_internal_compile_foreach.php
Expand Up @@ -219,8 +219,9 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if (isset($itemAttr[ 'index' ])) {
$output .= "{$itemVar}->index = -1;\n";
}
$output .= "if (\$_from !== null) {\n";
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->do_else = true;\n";
$output .= "if (\$_from !== null) foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->do_else = false;\n";
if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
}
Expand Down Expand Up @@ -296,7 +297,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n} else {\n?>";
$output .= "}\nif ({$itemVar}->do_else) {\n?>";
return $output;
}
}
Expand Down Expand Up @@ -332,9 +333,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
if ($restore > 0) {
$output .= "}\n";
}
$output .= "}\n";
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
Expand Down