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

Smarty2 $smarty.foreach.<name>.index comparison breaks in smarty 3.1 #41

Closed
jeffreydevreede opened this issue May 20, 2015 · 1 comment

Comments

@jeffreydevreede
Copy link

I am having a problem with upgrading from 3.0 to 3.1, some of our code uses smarty 2 style foreach loops. The comparison of the indexes is breaking.

This works in smarty 3.0 but breaks in 3.1:

{foreach from=['foo', 'bar', 'baz'] key="key" item="value" name="foobar"}
    {$smarty.foreach.foobar.index|var_dump}
    {if $smarty.foreach.foobar.index > 1}
        {$smarty.foreach.foobar.index|var_dump}
    {/if}
{/foreach}

Output in 3.0: int(0) int(1) int(2) int(2)
Output in 3.1: int(0) int(1) int(1) int(2) int(2)

I've also noticed that adding brackets around the index is a workaround for the problem.

{if ($smarty.foreach.foobar.index) > 1}

This is probably due to the fact that it compiles to the following code (null > 1).
Without brackets:

<?php if ((isset($_smarty_tpl->tpl_vars['__foreach_foobar']->value['index']) ? $_smarty_tpl->tpl_vars['__foreach_foobar']->value['index'] : null > 1)) {?>

With brackets:

<?php if ((isset($_smarty_tpl->tpl_vars['__foreach_foobar']->value['index']) ? $_smarty_tpl->tpl_vars['__foreach_foobar']->value['index'] : null) > 1) {?>```
uwetews added a commit that referenced this issue May 20, 2015
@uwetews
Copy link
Contributor

uwetews commented May 20, 2015

The patch is now in dev-master. It will be included in 3.1.24 which will be released very soon.

@uwetews uwetews closed this as completed May 20, 2015
think-mcunanan pushed a commit to think-mcunanan/smarty that referenced this issue Mar 22, 2023
…anzashi-account-settings-are-displayed-on-the-Shift/holiday-setting-screen

Ticket #5184 Display kanzashi and non kanzashi settings on the shift/holiday setting screen
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