{% include 'menu.html' %}
and then the bottom layer menu.html is something like
{% block menu-items %}
<li>Home</li>
{% endblock %}
and then an installed app higher in the load order makes its own menu.html
as follows:
{% extends 'menu.html' %}
{% block menu-items %}
{{ block.super }}
<li>My App</li>
{% endblock %}
Current test coverage has some similar cases in that they a) make an
included template with blocks and b) override those blocks, but there are
currently no tests that validate that {{ block.super }} works as expected
in that context.
Issue:
The current ExtendsNode behavior initializes the history from the
context's origin instead of the node's origin. This results in it making
two renders of the same origin, which in turn causes anything added
above/below {{block.super}} to render twice.
In the example above, I would end up with:
<li>Home</li>
<li>My App</li>
<li>My App</li>
Proposed Solution:
By changing the initial history entry to be the node's origin, we ensure
the behavior works correctly for both a base template and an included
template.
In the solution provided, a simple test is added to validate the behavior.
Before the change the test would fail because it would render the new
content in the block twice (first time the origin in the history is for
the context's base template, not the calling tag's template's origin),
which results in it adding the node's origin the first pass, and then
rendering it a second time before skipping it. This results in the
string: "12ABB"
After the change, we get the expected result of: "12AB"
--
Ticket URL: <https://code.djangoproject.com/ticket/28071>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => John D'Ambrosio
* status: new => assigned
Comment:
https://github.com/django/django/pull/8234
--
Ticket URL: <https://code.djangoproject.com/ticket/28071#comment:1>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28071#comment:2>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28071#comment:3>
* version: 1.11 => 1.9
Comment:
Adjusting versions affected--this has been around since recursive template
loading was introduced in 1.9.
--
Ticket URL: <https://code.djangoproject.com/ticket/28071#comment:4>
Comment (by John D'Ambrosio):
Updated per feedback from Tim Graham.
--
Ticket URL: <https://code.djangoproject.com/ticket/28071#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"be68c0bf637d9b28780753575b889946a734ca0e" be68c0b]:
{{{
#!CommitTicketReference repository=""
revision="be68c0bf637d9b28780753575b889946a734ca0e"
Fixed #28071 -- Fixed {% extends %} origin history.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28071#comment:6>