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

ForCompiler bug #88

Open
apsavin opened this issue Feb 10, 2015 · 3 comments
Open

ForCompiler bug #88

apsavin opened this issue Feb 10, 2015 · 3 comments
Labels

Comments

@apsavin
Copy link

apsavin commented Feb 10, 2015

We can use the following code inside twig templates: {{ loop.parent.loop.index0 }}
It works great on our server, where twig compiles into php files, but it doesn't work when we try to compile it in JavaScript.

You can fix it very easy, just replace this line with the following:

->write("'parent': {loop: loop$parentSuffix},\n")

and merge other things to the parent context.

@zmajciki
Copy link

I think that this change produced another bug with nested loop. For example, this code compiles well

{% for dd in data %}
    {{ loop.index }} {# parent loop index #}
    {% for d in dd %}
        {{ loop.index }} {# child loop index #}
    {% endfor %}
{% endfor %}    

But this one desn't:

{% for dd in data %}
    {% for d in dd %}
        {{ loop.index }} {# child loop index #}
    {% endfor %}
{% endfor %}

I think that it is because when the loop variable is used in parent for it sets its attribute "with_loop" to true and adds loop variable in JS.

When parent do not use the loop variable then parent's "with_loop" is not set so variable loop is not set, but it is used in child for.

@apsavin
Copy link
Author

apsavin commented Mar 30, 2015

This change wasn't merged

@zmajciki
Copy link

Sorry, my bad, both lines look very similar.

Either way, bug exists, and is coused by reference to nonexisting loop variable (which does not exits if parent doesn't use loop in its body).

@henrycatalinismith henrycatalinismith changed the title ForCompiler is broken ForCompiler bug Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants