-
Notifications
You must be signed in to change notification settings - Fork 638
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
Inconsistent scoping behavior in "macro", "include" and template inheritance. #561
Comments
There's a similar weirdness happening with the include tag as well. Given this simple template...
...you get two very different results when you include it. First...
...evaluates to "" (the empty string). The value of var does not leak out of the included template's scope. This template, however, does leak its scope...
...evaluating to "22". In Jinja, these two templates evaluate to "" and "44", respectively, as before. |
Thanks for tracking this down! This is definitely something that should ideally be fixed, though without diving into the details I have no idea how invasive the fix will be. It's something I'd enjoy looking into if I find some time, but not sure when that will be - pull requests definitely welcome! (Even just a PR with failing tests for these issues would be a really good start.) |
I discovered more of the same weirdness with template inheritance. Given this base template...
...when you execute the following template...
...you get the expected result: ‘child’. This is the same value that Jinja emits. However, when you execute the following template...
...you get ‘parent’. Again, the problem is a leaking scope (in this case, that of “super()”), but only when the value is set. With Jinja, in this second case, you get ‘’ (i.e. the empty string). And there is also a fourth inconsistency. Given this base template...
...when you execute the following template...
...you get ‘child’. The child block is leaking into the parent template. However, when you render the “base2.html” file directly, the block scope does not leak, and the template renders ‘parent’, as expected. In Jinja, both templates render to the string ‘parent’. I hope that I will be able to help with this. If I have time, I will definitely work on it, but I'm not sure if I will. |
The macro portion of this should be fixed with the merge of #653 -- the |
Ok, I think that concludes the last of this bug, finally! Thanks again @legutierr for digging up these issues; please feel free to dig some more and see what you find :-) |
* master: (88 commits) Bump versions for dev. Update maintenance docs. Revert accidental changes to mocha.js. Bump version to 2.4.0. Update changelog. Merge pull request #694 from mariusbuescher/master Update changelog. Add support for boolean globals Add note about include and blocks; update wrapping of templating docs. Merge pull request #688 from pra85/patch-1 Add note about include and blocks; update wrapping of templating docs. Update api.md fixed bad character leading % in {% endraw %} Respect null/none as a value in its own right, distinct from undefined. Fixes #478. Use dot reporter for npm test. Don't bail on first failed test in 'npm test'. Add acknowledgement for #561 to changelog. Tighter scoping of vars in blocks, to match Jinja2. Fixes #561. Rename all test templates to use .j2 extension. Rename all test templates to use .j2 extension. ...
This template...
...evaluates to "" (i.e., the empty string). The value set inside the macro doesn't leak out of the the local macro scope. However, this template...
...evaluates to "22". The value set inside the macro leaks out of the macro scope. In Jinja, these two templates evaluate to "" and "44", respectively.
The text was updated successfully, but these errors were encountered: