Variables and templates inheritance

In Nunjucks, inheriting templates can have private variables.

Variables and blocks

When you rely on template inheritance using the {% extends %} declaration , you cant’ have a {% block %}{% endblock %} inside a variable set block. The other way, a variable declared inside a {% block %}{% endblock %} will not be accessible outside. Therefore, you can’t gather all variables in a global variable passed as an argument to the processing filter. However, you still have the possibility to process each block individualy.

Variables scope

When using variables declared with the set block, never forget that any variable whose name begins with one or more underscore character is private. Therefore it can not be imported outside of its block scope unfortunatly, the Nunjucks documentation doesn’t state it: I found this important note in the Jinja2 documentation. .