The block is a core feature in the template system. Currently, the syntax provides no explicit grammar to differentiate between a placeholder and a content provider. It would be nice to have a way to mark a block as a content provider and differentiate it from a placeholder. This would enhance readability, and open the door to other possibilities. Here is an example to illustrate the proposed syntax:
{% block usertools = %} my user tools {% endblock %}
Note the equal sign in the end of the block opening tag, which is an element added here to indicate that this is a content provider for the block named ‘usertools’ defined somewhere else. The ‘=’ sign is analogous to that in an assignment statement in most programming languages, since a content provider block can be seen as assigning a value or content to a block. Viewed in this way, hopefully the syntax now looks more natural and meaningful. If one would like to append some extra content to this block, it can be done as follows:
{% block usertools += %} additional user tools {% endblock %}
Besides enhancing readability, I think there can be a lot of other benefits with this syntax, such as having a block accumulate contents gradually based on different conditions:
{% block usertools = %} my user tools {% endblock %}
{% if user.authorized %}
{% block usertools += %}, extra user tools {% endblock %}
{% endif %}
In this illustration, if user.authorized is False, then the block content is simply ‘my user tools’, otherwise, it would be ‘my user tools, extra user tools’. This would make the block content specification more flexible and convenient.
It may open the door for other possibilities with this syntax. For example, multiple occurrences of such content providers for the same block can exist in a single template file, which was requested several times in the past.
It would be super nice to hear what the community thinks about this, thanks a lot.