You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to access the loop variable loop inside a nest block (even with the scoped argument) causes Jinja to report an undefined-error during rendering.
Ability to access the loop variable in the nested block. The example above should produce:
Spam
Foo a
Foo list
Foo of
Foo items Bar
Eggs
Actual Behavior
Jinja reports an undefined-error
Full Traceback
Traceback (most recent call last):
File "render.py", line 6, in <module>
rendered = template.render()
File "~/.local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in renderreturn original_render(self, *args, **kwargs)
File "~/.local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in renderreturnself.environment.handle_exception(exc_info, True)
File "~/.local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "~/.local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraiseraise value.with_traceback(tb)
File "./template.txt", line 3, in top-level template code
{% block spamblock scoped -%}
File "./template.txt", line 4, in block "spamblock"
Foo {{ item }} {%if loop.last %}Bar{% endif %}
File "~/.local/lib/python3.7/site-packages/jinja2/environment.py", line 430, in getattrreturngetattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'loop' is undefined
Your Environment
Python version: 3.7.3 [GCC 8.3.0] on linux
Jinja version: 2.10.1
Workaround
Simply setting the loop variable to another, and using the other variable inside the nested block (and overrided blocks in inheriting child templates):
Trying to access the loop variable
loop
inside a nest block (even with thescoped
argument) causes Jinja to report an undefined-error during rendering.Template Code
Expected Behavior
Ability to access the loop variable in the nested block. The example above should produce:
Actual Behavior
Jinja reports an undefined-error
Full Traceback
Your Environment
Workaround
Simply setting the loop variable to another, and using the other variable inside the nested block (and overrided blocks in inheriting child templates):
The text was updated successfully, but these errors were encountered: