Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#501 closed enhancement (fixed)

{{ block.super }} returns value of the most remote ancestor

Reported by: eugene@… Owned by: Adrian Holovaty
Component: contrib.syndication Version: 0.90
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

{{ block.super }} always returns value of the most remote ancestor. Example:

Template A:

{% block abc %}A{% endblock %}

Template B:

{% extends "A" %}
{% block abc %}{{ block.super }}B{% endblock %}

Template C:

{% extends "B" %}
{% block abc %}{{ block.super }}C{% endblock %}

Template A will be rendered as "A", B as "AB", C as "AC". I assume the original intention was to implement a stack of parents, so C would be rendered as "ABC". At least it is documented that way.

template_loader.py doesn't implement stacking order for blocks. Instead it defines two member variables in BlockNode: nodelist, which holds current nodes, and original_node_list, which holds nodes of the farthest ancestor.

Attachments (1)

block_super_fix.diff (3.8 KB) - added by django@… 11 years ago.
A hack for this problem and some unit tests

Download all attachments as: .zip

Change History (6)

Changed 11 years ago by django@…

Attachment: block_super_fix.diff added

A hack for this problem and some unit tests

comment:1 Changed 11 years ago by django@…

I have a set of templates that depend on {{ block.super }} working as described by Eugene. This little hack does the job for me. Even if you think the fix sucks the unit tests may be useful.

Cheers,
Kieran

comment:2 Changed 11 years ago by Adrian Holovaty

Status: newassigned

comment:3 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: assignedclosed

(In [715]) Fixed #501 -- Fixed block.super in multi-level templates, and added unit tests to confirm. Thanks for the patch, django@…

comment:4 Changed 10 years ago by anonymous

Component: Template systemRSS framework
milestone: Version 1.0
priority: normallow
Severity: normalminor
Type: defectenhancement
Version: 0.9

comment:5 Changed 10 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

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