[ACCEPTED]-Multiple blocks of same name in Jinja2-jinja2
Accepted answer
As documented here, defining a block creates 2 a macro with the name of the block in the 1 special "self" object:
<title>{% block title %}{% endblock %} - example.com</title>
[...]
<h1>
{{ self.title() }} - example.com
</h1>
The idea is to create a block inside a macro 3 and then call macro two times, instead of 2 having "block" tag repeated twice.
In latest 1 Jinja2 version this works:
layout.html
{%- extends "base.html" -%}
{%- macro duplicated() -%}
{% block overrideninchild %}{% endblock %}
{%- endmacro -%}
{% block base_content %}
{{ duplicated() }}
{{ duplicated() }}
{% endblock %}
child_page.html
{%- extends "layout.html" -%}
{% block overrideninchild %}
Should be visible twice.
{% endblock %}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.