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

Cannot reference outer scopes from inside a {% call %} block. #679

Open
carljm opened this issue Feb 18, 2016 · 7 comments
Open

Cannot reference outer scopes from inside a {% call %} block. #679

carljm opened this issue Feb 18, 2016 · 7 comments
Labels

Comments

@carljm
Copy link
Contributor

carljm commented Feb 18, 2016

Originally reported by @jgerigmeyer at #481 (comment) -- all of the below copied from his report:

Consider the following test case:

{% macro inner(class=none) %}
  <div class="{{ class }}">{{ caller() }}</div>
{% endmacro %}

{% macro outer(class=none) %}
  <div class="{{ class }}">
    {% call inner() %}
      {{ class }}
    {% endcall %}
  </div>
{% endmacro %}

{{ outer(class='outer') }}

Jinja2 outputs as expected:

<div class="outer">
  <div class="None">
    outer
  </div>
</div>

But nunjucks outputs:

<div class="outer">
  <div class="">
  </div>
</div>
@carljm
Copy link
Contributor Author

carljm commented Feb 18, 2016

This is related to #664; it has to do with how the frame stack for a {% call %} block is constructed.

@carljm carljm added the bug label Feb 18, 2016
@atheros
Copy link

atheros commented Mar 13, 2017

This is a very annoying bug. You cannot take full advantage of call/caller feature without it.

Are there any plans for fixing this bug?

@ArmorDarks
Copy link

yeap, macros scopes are kinda buggy right now :(

@atheros as far as I remember, making call with {% call %} makes it work:

{% call outer(class='outer) %}{% endcall %}

Ugly, but better than nothing.

@atheros
Copy link

atheros commented Mar 14, 2017

It doesn't work, the result is the same.

@ArmorDarks
Copy link

You're probably on Nunjucks 3.0.0? As far as I remember, in 3.0.0 it is impossible to pass external variable into macros at all, due to bug described here #912

@atheros
Copy link

atheros commented Mar 15, 2017

Yes, 3.0.0. And I cannot pass variables to call block, which pretty much makes call useless, except for very simple cases.

Anyway downgrading to 2.5.2 fixes the issue. Thanks for the hint @ArmorDarks

Interestingly, set block in macros doesn't work there (bug #914), so it's an older issue.

@jgerigmeyer
Copy link
Contributor

I note that this bug still exists in v3.2.0.

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

4 participants