Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override nested blocks in Jinja2

Tags:

python

jinja2

If I define a block inside a block in a Jinja template, and extend it, How do I reference the nested block in the child template?

like image 458
abc def foo bar Avatar asked Mar 25 '11 18:03

abc def foo bar


1 Answers

You reference the nested block the same way you reference any block, e.g., given

{% block outer_block %} 
  Outer things
  {% block inner_block %}
    Inner things
  {% endblock %}
  More outer things
{% endblock %}

You'd override inner_block with

{% block inner_block %} 
   customized inner content
{% endblock %} 

Can you clarify what problem you're encountering? Or are you running into scoping issues, e.g., http://jinja.pocoo.org/docs/templates/#block-nesting-and-scope ?

like image 183
A Lee Avatar answered Oct 07 '22 13:10

A Lee