Ticket #345 (closed enhancement: wontfix)
for loop var should be available to contextfunction
| Reported by: | jpellerin | Owned by: | mitsuhiko |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | general | Version: | dev |
| Keywords: | Cc: |
Description
Given a template like:
{% for a in [1, 2, 3] %}
{{ somefunc() }}
{% end for %}
And assuming somefunc() is a contextfunction, I expected 'a' to be available in somefunc()'s context, but it isn't. I find this very counter-intuitive.
The same is true of variables set inside of a for loop via {% set %}.
In both cases, instead of a locally-scoped context, or updating context.vars, jinja2 only creates local vars in the generated python code, which prevents contextfunctions and contextfilters from seeing them.
Change History
Note: See
TracTickets for help on using
tickets.