#7324: {{ block.super }} doesn't work with nested {% block %} statements
--------------------------------------+-------------------------------------
          Reporter:  jeverling        |         Owner:  nobody              
            Status:  closed           |     Milestone:                      
         Component:  Template system  |       Version:  SVN                 
        Resolution:  invalid          |      Keywords:  block.super template
             Stage:  Unreviewed       |     Has_patch:  0                   
        Needs_docs:  0                |   Needs_tests:  0                   
Needs_better_patch:  0                |  
--------------------------------------+-------------------------------------
Comment (by kmtracey):

 OK, just for clarity and so people don't have to unzip the project.  The
 parent template `new/test.html` contains:

 {{{
 {% block main %}
     New content
     {% block submain %}This should be inherited{% endblock %}
 {% endblock %}
 }}}

 The child template, `templates-top/test.html` contains:

 {{{
 {% extends "new/test.html" %}
 {% comment %}Gets around infinite recursion bug by namespacing with a
 directory{% endcomment %}
 {% block main %}
     Top-level main block
     {% comment %}remove this block.super and it all disappears. But I only
 want the block.super from inside "submain"{% endcomment %}
     {{ block.super }}
     {% block submain %}
         my new sub-content
         {{ block.super }}
         {% comment %}I expect this block.super to contain the content of
 "submain" from new/test.html, because I'm extending it. It is empty,
 UNLESS "main" has a block.super call, in which case it's echoed TWICE{%
 endcomment %}
     {% endblock %}

 {% endblock %}

 }}}

 Consider what the child template is doing.  By including a {% block main
 %} it is saying "I want to override the contents of the block named "main"
 in the parent template with this content I am specifying here."  When it
 does that, block "submain" ceases to exist, as the "submain" block was
 declared within block main in the parent.  If you discard the contents of
 the parent template's main block in favor of what is in the child
 template, then you lose the "submain" block entirely.  You can get it back
 by including block.super in the child's "main" override, but then anything
 else you have in the child's "main" is simply appended to the parent's
 "main" content, which doesn't seem to be what you want.

 I said this earlier and I'll say it again: django-users would be a better
 place to outline what you are looking to achieve and get ideas on how to
 accomplish it.  There is a much larger audience there than in the ticket
 system.  So far as I can see there is not a bug here, it's just a case of
 the template inheritance mechanism not quite working the way you'd like it
 to.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/7324#comment:6>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to