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
{foreachelse} not showing with Iterator 0 elements #562
Comments
What Smarty version did you use before? |
It was working with 3.1.14 |
Could you try with 3.1.30 and 3.1.31 please? If it works in 3.1.30, but not in 3.1.31, it's probably due to this change: Lines 302 to 303 in b2ecd98
|
I've tested and it works correctly with 3.1.31, 3.1.32 Problem only occurs when using objects like class that implements iterator. |
this was fixed in #566 |
Recently updated to PHP7.3 and Smarty 3.1.34 and noticed that {foreachelse} is not executed when the data count is 0.
I think this is because $needTotal parameter in smarty_internal_runtime_foreach.php:44 is false and $total will always be 1 so function will not return null if total items in array/Iterator is 0.
smarty_internal_runtime_foreach.php
if (!isset($total)) {
$total = empty($from) ? 0 : ($needTotal ? count($from) : 1);
}
......
if ($total === 0) {
$from = null; //should return 0 if {foreachelse} is used
} else {
To fix this smarty_internal_compile_foreach.php:190 should check if total is needed and/or foreachelse tag is present. I have added "|| true" so it will always do a count() on the supplied array. Not best fix but I don't know how to check if a {foreachelse} tag is present.
smarty_internal_compile_foreach.php:190
$needTotal = isset($itemAttr[ 'total' ]) || true; //check if {foreachelse} tag is present instead of || true ...
The text was updated successfully, but these errors were encountered: