Jinja

python template engine


Ticket #345 (closed enhancement: wontfix)

Opened 10 months ago

Last modified 5 weeks ago

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

Changed 10 months ago by jpellerin

Draft implementation can be pulled from bitbucket here: https://bitbucket.org/jpellerin/jinja2-main

Changed 5 weeks ago by mitsuhiko

  • status changed from new to closed
  • resolution set to wontfix

It is documented that the context is only used as a data source, not data store. This is impossible with the current architecture to get right, and changing that would make the whole template execution a lot slower.

Note: See TracTickets for help on using tickets.