Let’s say I have the three html template files shown below. HTML is minimal just to illustrate the point.
Is it possible to somehow nest a block named extra_head_content inside of a block already named extra_head_content. The idea is to allow the third-level template to provide a block named extra_head_content. The template above it takes that content, adds it to its block named extra_head_content and provides this combined block to its parent template.
Essentially, I am looking for block nesting across inherited template files.
The exact scenario I am trying to solve is that any template should be able to add extra javascript or css files to the head element. However, the lowest template should not care how many levels down it is nested. Similarly, the extra head content provided by an intermediate template should not get overwritten by the block element of the terminal template.
base.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/css/reset.css" />
{% block extra_head_content %}{% endblock %}
</head>
<body>{% block content %}{% endblock %}
</html>
account.html
{% extends "base.html" %}
{% block extra_head_content %}
<link rel="stylesheet" type="text/css" href="/static/css/account.css" />
{% block extra_head_content %}{% endblock %}
{% endblock %}
{% block content %}
<div id="menu">...</div>
{% block account_content %}{% endblock %}
{% endblock %}
account_profile.html
{% extends "account.html" %}
{% block extra_head_content %}
<link rel="stylesheet" type="text/css" href="/static/css/edit_profile.css" />
{% endblock %}
{% block account_content %}
Welcome to your profile
{% endblock %}
No, but you can use
{{ block.super }}: