[Answered ]-Jinja : access parent variable from child

1๐Ÿ‘

โœ…

I ended up adding an import under the extends, and it works so far.

Working example :

parent.j2

{% set foo = foo|default("foo") %}
{% set from_parent = "ok" %}

child.j2

{% extends 'parent.j2' %}
{% import 'parent.j2' as parent with context %}
{% set foo = "bar" %}
{% set to_child = parent.from_parent %}

Output :

foo : "bar"

to_child : "ok"

๐Ÿ‘คksm101

Leave a comment