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

Nested {foreach} iteration, index and total property values are invalid. #316

Closed
sowizz opened this issue Nov 17, 2016 · 1 comment
Closed

Comments

@sowizz
Copy link

sowizz commented Nov 17, 2016

Hi, I have a template file with nested {foreach} that creates a table that is filled with content:

$data: array(
  row1: array(
    col1: array(...)
    col2: array(...)
  ),
  row2: array(
    col1: array(...)
  )
)

Each row can have maximum of 2 columns, and if there is only one column a dummy one is added after nested foreach. So the code looks like this:

{foreach from=$data item='row'}
  {foreach from=$row item='col'}
    (insert column content)
  {/foreach}
  {if col@iteration == 1} // Also used total and index 
    (insert dummy column)
  {/if}
{/foreach}

The problem does not occur when there is only one row and one column, dummy column is added. But if I have 3 items (2 rows, 1. has two columns and 2. has one) col@iteration is equal to two somehow, so dummy column is not added.

Changing if statement to {if $row|@count === 1} solves the problem so my guess is that there is something wrong with smarty after recent update (the current version we use is 3.1.30, the previous one was 3.1.27 end original if statement was working.

@uwetews
Copy link
Contributor

uwetews commented Nov 19, 2016

This is the same problem as #267
The fix is in the master branch

@uwetews uwetews closed this as completed Nov 19, 2016
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