I've got a template parent.tpl
:
{% set myvar = 'AAA' %}
{% block par %}
{{ myvar }}
{% endblock %}
and a child.tpl
{% extends "parent.tpl" %}
{% block par %}
{% set myvar = 'BBB' %}
{{ super() }}
{% endblock %}
the child.tpl
results:
AAA
but not
BBB
How can I get BBB
output with variable override?
Thanks
If you're using Flask, you can use a global variable like g.myvar
. It will be available in every template.
Take a look at Pass variables from child template to parent in Jinja2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With