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

Property @iteration on foreach items is undefined under some circumstances #484

Closed
obokaman-com opened this issue Aug 31, 2018 · 1 comment

Comments

@obokaman-com
Copy link

obokaman-com commented Aug 31, 2018

We've been using Smarty for a while and today, even while we are using v3, we still have some templates that "mix" foreach loops with the "old" syntax from Smarty 2, like following:

{foreach name=grapes item=grape from=$product.attributes.grapes.values}
{if $smarty.foreach.grapes.first}
foo,
{else if $grape@iteration > 1}
bar,
{/if}
{/foreach}

At least until 3.1.24 (the version from where we are updating now) we could use both syntax, but with 3.1.32, if we use the "name" property on foreach, using @iteration from inside the loop launches an undefined property error.

If we remove the "name" property on the foreach or use the syntax {foreach $product.attributes.grapes.values as $grape}, iteration has its value correctly.

Thanks for your help!

uwetews added a commit that referenced this issue Sep 2, 2018
…ty} on

    Smarty 2 style named foreach loop could produce errors #484
@uwetews uwetews closed this as completed Sep 2, 2018
@obokaman-com
Copy link
Author

Thanks @uwetews! 👏 🔝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants