Jinja: Cannot override blocks in included templates

Created on 8 Jan 2013  路  3Comments  路  Source: pallets/jinja

We're trying to override a block in an included template like this:

#included.jinja2

{% block master %}
    Default master content
{% endblock %}
#base.jinja2
{% include "included.jinja2" %}
{% include "included.jinja2" with context %}

{% block master %}
Fnord
{% endblock master %}
#hello.jinja2
{% extends "base.jinja2" %}

{% block master %}

Overridden master content

{% endblock master %}

When running the hello.jinja2 file we see this output

    Default master content
    Default master content
Overridden master content

I would have expected at least the second default master content to be replaced by the overriden content.

That I think is the bug.

All 3 comments

Duplicate.

of?

Edit: Which issue is this a duplicate of?

ugh, to make matters worse, Django templates don't do it either (see note at the end: https://docs.djangoproject.com/en/1.11/ref/templates/builtins/#include)

i thought maybe jinja2 would, it'd save me a heck of a lot of duplication >_<

anyway, I guess I'll just have to find a way to simplify stuff down :(

Was this page helpful?
0 / 5 - 0 ratings