Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#33317 closed Cleanup/optimization (fixed)

Add note about not overriding parent blocks within conditionals

Reported by: Nat S Dunn Owned by: Victor
Component: Documentation Version: 3.2
Severity: Normal Keywords: block, if, Template inheritance
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes 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. But according to Mariusz Felisiak's response at https://code.djangoproject.com/ticket/33311, this is by design.

It would be great if this could be added to the documentation on Template Inheritance.

Change History (7)

comment:2 by Mariusz Felisiak, 3 years ago

Triage Stage: UnreviewedAccepted

Agreed, a small note may be helpful.

Last edited 3 years ago by Mariusz Felisiak (previous) (diff)

comment:3 by Mariusz Felisiak, 2 years ago

Easy pickings: set

comment:4 by Victor, 2 years ago

Owner: changed from nobody to Victor
Status: newassigned

comment:5 by Victor, 2 years ago

Here is a link to my pull request : https://github.com/django/django/pull/15865

comment:6 by Mariusz Felisiak, 2 years ago

Has patch: set

comment:7 by GitHub <noreply@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 2fac0a18:

Fixed #33317 -- Added note about unconditional evaluation of {% block %} tags.

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 8a2e65c2:

[4.1.x] Fixed #33317 -- Added note about unconditional evaluation of {% block %} tags.

Backport of 2fac0a18081dcc77fc860c801e5d727dc90435b3 from main

Note: See TracTickets for help on using tickets.
Back to Top