We recently started upgrading from jinja to jinja2 and ran into a
rather large road block. Basically, in jinja2 templates rendered via
{% include %} do not have access to variables defined in the parent
template.
So the following would print nothing:
# parent template
{% for value in values %}
{% include "test_include" %}
{% endfor %}
# test include
{{ value }}
Was this change in behavior intended when writing jinja2?
Here is a complete test case which compares jinja (which works as
expected) and jinja2:
def testTemplate ():
return '''
{% for value in values %}
<div>Value in main: {{ value }}</div>
{% include "test_include" %}
{% endfor %}
'''
def testInclude ():
return '<div>Value in include: {{ value }}</div>'
def load (name):
if name == 'test_include':
return testInclude()
return testTemplate()
def testJinja ():
from jinja import Environment, FunctionLoader
j = Environment(loader=FunctionLoader(load))
print j.get_template('test').render(values=['one', 'two', 'three'])
def testJinja2 ():
from jinja2 import Environment, FunctionLoader
j2 = Environment(loader=FunctionLoader(load))
print j2.get_template('test').render(values=['one', 'two', 'three'])
print '############ Test Jinja ############'
testJinja()
print '############ Test Jinja2 ############'
testJinja2()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---