Opened 3 years ago

Closed 3 years ago

#33291 closed New feature (wontfix)

Allow blocks with same name in if/else

Reported by: Ahmed Saoudi Owned by: nobody
Component: Template system Version: 3.2
Severity: Normal Keywords: template, block
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Apparently, the Django template system doesn't allow for a block to appear more than once even within an if/else conditional, even if this means that, practically, the block will appear only once:

{% if condition %}
  {% block title %}title with {{ variable }}{% endblock %}
{% else %}
  {% block title %}static title{% endblock %}
{% endif %}

Allowing the block to appear more than once in such a setting may, IMHO; render things way more simple to handle.

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: wontfix
Status: newclosed
Type: BugNew feature

Thanks for this ticket, however this limitation is documented:

Finally, note that you can't define multiple block tags with the same name in the same template. This limitation exists because a block tag works in "both" directions. That is, a block tag doesn't just provide a hole to fill - it also defines the content that fills the hole in the parent. If there were two similarly-named block tags in a template, that template's parent wouldn't know which one of the blocks' content to use.

Moreover, this was already discussed on the mailing list. See related tickets closed as "wontfix": #20219, #24232, and #4529.

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