#28071: ExtendsNode history initialized with context origin rather than own
origin
-------------------------------------------+------------------------
Reporter: John D'Ambrosio | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
While the "extends" tag and blocks are typically used to extend a base
template, one can also leverage it to extend an included template with
blocks, as long as the rules of block inheritance are respected. A use
case for this might be a base template that includes a menu stub:
{% 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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.6bde95af09f49cd0f0829557029442a3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.