Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#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 %}

Change History (1)

comment:1 by Mariusz Felisiak, 2 years ago

Resolution: duplicate
Status: newclosed

This is by design, see also discussions in related tickets #13399, #20219, #24232, and #4529.

Duplicate of #13413.

Last edited 2 years ago by Mariusz Felisiak (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top