#33311 closed Cleanup/optimization (duplicate)
Disallow overriding parent blocks within conditionals.
Reported by: | Nat S Dunn | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 3.2 |
Severity: | Normal | Keywords: | block, conditional, if |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When a parent block is overridden in an if condition, the overridden content is output regardless of the truthiness of the condition. For example:
{% if False %} {% block parent %}Foo{% endblock parent %} {% endif %}
Foo gets output, which feels wrong. Either this structure should be disallowed or the behavior should change.
If Django disallows overriding parent blocks within conditionals, then it would be great if the error message could include a hint describing the following workaround:
{% block parent %} {% if False %} {% block parent %}Foo{% endblock parent %} {% else %} {{ block.super }} {% endif %} {% endblock parent %}
Note:
See TracTickets
for help on using tickets.
This is by design, see also discussions in related tickets #13399, #20219, #24232, and #4529.
Duplicate of #13413.