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

Foreach {$item@index} and {$item@iteration} not recognized in a included template #189

Closed
yourchoice opened this issue Feb 20, 2016 · 2 comments

Comments

@yourchoice
Copy link

Foreach {$item@index} and {$item@iteration} not recognized in a included template:

{foreach $last_articles as $item}
    {$item@index}.{$item@iteration}.
    {include 'site/inc/article_item.tpl'}
{/foreach}

Here, in the template article_item.tpl I want to use : {$item@index}.{$item@iteration}, but are not recognized. Data like: {$item.article_title}, {$item.article_text} is recognized.

I use smarty 3.1.30-dev/41

uwetews added a commit that referenced this issue Feb 20, 2016
… of 10.2.2016 #184

  - new feature/bugfix {foreach}{section} new attribute 'property' to force compilation of loop property
    read NEW_FEATURES.txt #189
@uwetews
Copy link
Contributor

uwetews commented Feb 20, 2016

I think

{foreach $last_articles as $item}
    {$item@index}.{$item@iteration}.
    {include 'site/inc/article_item.tpl'}
{/foreach}

does work

but

{foreach $last_articles as $item}
    {include 'site/inc/article_item.tpl'}
{/foreach}

does not

Foreach runtime optimization does remove code for properties not used.
However the compiler can only check the current template for used properties.
So in first example $item.index and $item.iteration are created, but not in the second.

There is now a new attribute 'properties' which does force compilation of properties which might be used outside the current template scope.

{foreach $last_articles as $item, properties=[index,iteration]}
    {include 'site/inc/article_item.tpl'}
{/foreach}

read NEW_FEATURES.txt

The fix is now in the master branch

@uwetews uwetews closed this as completed Feb 20, 2016
uwetews added a commit that referenced this issue Feb 20, 2016
… of 10.2.2016 #184

  - new feature/bugfix {foreach}{section} new attribute 'property' to force compilation of loop property
    read NEW_FEATURES.txt #189 (reverted from commit 4958dea)
uwetews added a commit that referenced this issue Feb 20, 2016
… force compilation of loop properties

    see NEW_FEATURES.txt #189
@ophian
Copy link

ophian commented Feb 21, 2016

However the compiler can only check the current template for used properties.
There is now a new attribute 'properties' which does force compilation of properties which might be used outside the current template scope.

If you add this (concerning current and outside scope template) to the new features text it is much clearer, IMHO.

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

3 participants