Opened 13 years ago

Closed 13 years ago

#17524 closed New feature (wontfix)

self referential blocks

Reported by: pasquinelli@… Owned by: nobody
Component: Template system Version: 1.3
Severity: Normal Keywords: recursive blocks
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

say i have a {% block content %} in base.html and i'd like to refine it in another template refined.html, while still exposing the block to other templates that extend from refined.html like so:

{% block content %}
   <div class="someclass">
      {% block content %}{% endblock content %}
   </div>
{% endblock content %}

currently this is impossible because there can be only one occurrence of a block in a template, which means i have to repeat myself. i think you should be able to override a block and still expose it for further extension.

Change History (3)

comment:1 by Russell Keith-Magee, 13 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #4529, and others. I think you might be looking for the {% include %} tag.

in reply to:  1 comment:2 by pasquinelli@…, 13 years ago

Resolution: duplicate
Status: closedreopened

Replying to russellm:

Duplicate of #4529, and others. I think you might be looking for the {% include %} tag.

wouldn't using the {% include %} tag require that the template know about the template that extends it, either by hard coding the name or through a context variable? isn't the purpose of blocks to allow the template to be extended to not have to know about the template doing the extending?

#4529 is about using a block as a variable, to repeat content. this is about a base template defining some of the contents of a block from the base template it extends, and then allowing the rest of the content to be supplied by subtemplates that refer to the same block. just to clarify, i'm not suggesting that multiple occurrences of a block should be legal, just nested occurrences of a block.

comment:3 by Luke Plant, 13 years ago

Resolution: wontfix
Status: reopenedclosed

You can do this by calling the inner block something different e.g. contentinner. Any templates that inherit from refined.html will know which template they are inheriting from, therefore can know to override 'contentinner' and not 'content'.

Having nested blocks with the same name is confusing - it's really not obvious which one you want to override. Therefore closing WONTFIX, since I can't see a use case for this that can't be achieved by less confusing means.

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