Opened 17 years ago

Closed 10 years ago

#6646 closed Bug (wontfix)

included template blocks are not being overridden by parent template.

Reported by: anonymous Owned by:
Component: Template system Version: dev
Severity: Normal Keywords: include, extends, block
Cc: michael@…, tom@…, mmitar@…, drackett@…, dueSouth, botondus@…, dev@…, flisky Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

When including a template into a parent template, the child-template's blocks are not overridden by the parent.

For example:

base.html:

{% if is_satchmo %}
{% include "satchmo_base.html" %}
{% else %}
{% include "journal_base.html" %}
{% endif %}

journal_base.html contains the following block:

{% block content%}{% endblock %}

view_template.html extends base.html (with the context variable is_satchmo == False). view_template.html contains {% block content%}{% endblock %} which should filled with data from the view's context variable.

If I rename journal_base.html to base.html - everything works fine - but when I use the version of base.html that relies on the include tag, {% block content %} doesn't get overridden.

The documentation says that context vairables are available to included templates, so not being able to override blocks seems like a bug.

Attachments (2)

6646.diff (3.0 KB ) - added by miracle2k 16 years ago.
includes tests
6646.2.diff (3.0 KB ) - added by Chris Beaven 15 years ago.

Download all attachments as: .zip

Change History (26)

comment:1 by Collin Grady <cgrady@…>, 17 years ago

Context variables have nothing to do with blocks - as far as I'm aware this is just how the template system works - included templates cannot be extended.

comment:2 by edgarsj, 17 years ago

Component: Template systemDocumentation
Triage Stage: UnreviewedAccepted

Probably documentation needs to clarify this.

comment:3 by Ramiro Morales, 17 years ago

Description: modified (diff)

comment:4 by miracle2k, 16 years ago

Cc: michael@… added

by miracle2k, 16 years ago

Attachment: 6646.diff added

includes tests

comment:6 by miracle2k, 16 years ago

Has patch: set

comment:7 by cornbread, 16 years ago

Why is this documentation? When can we see it in trunk?

comment:8 by Collin Grady, 16 years ago

it is documentation because it is not supposed to work - as such, it needs documented that this is the case, so that people don't think it's a bug

comment:9 by walpatal, 15 years ago

Owner: changed from nobody to walpatal

I've been biten by this enough times to take a stab solving it.

by Chris Beaven, 15 years ago

Attachment: 6646.2.diff added

comment:10 by Chris Beaven, 15 years ago

Component: DocumentationTemplate system
Needs documentation: set

There's no reason this can't work (for static include blocks), so I'm switching the component back to "template system".

I've attached an updated patch which does it a bit safer than miracle2k's way (the way that Node.get_nodes_by_type() works, if nodelist attribute is there, it currently assumes it's a NodeList and not None so a nodelist property doesn't work)
We do need some documentation to say that dynamic include blocks won't be extended. Wanna write something up walpatal?

comment:11 by Marco Paolini, 15 years ago

a different but somewhat related feature is selective include tag #11832

comment:12 by Thomas Steinacher <tom@…>, 15 years ago

Cc: tom@… added

The patch is working for me. Any reason this is not in trunk yet?

in reply to:  12 comment:13 by Luke Plant, 15 years ago

Replying to Thomas Steinacher <tom@eggdrop.ch>:

The patch is working for me. Any reason this is not in trunk yet?

Without docs for the point SmileyChris mentioned it won't go in. Also, I suspect that fixing #12064 would break this patch, because it effectively makes all include blocks 'dynamic' i.e. the actual template used is decided at render time, not compile time. If my suspicions are correct, then there are definitely some design decisions to be made.

comment:14 by walpatal, 15 years ago

Owner: walpatal removed

comment:15 by Mitar, 14 years ago

Cc: mmitar@… added

comment:16 by chrisdrackett, 14 years ago

Cc: drackett@… added

comment:17 by Julien Phalip, 14 years ago

Type: Bug

comment:18 by Julien Phalip, 14 years ago

Severity: Normal

comment:19 by dueSouth, 13 years ago

Cc: dueSouth added
Easy pickings: unset
UI/UX: unset

comment:20 by Béres Botond, 13 years ago

Cc: botondus@… added

comment:21 by Brillgen Developers, 13 years ago

Cc: dev@… added

comment:22 by flisky, 13 years ago

Cc: flisky added

comment:23 by Jannis Leidel, 12 years ago

Summary: included template blocks are not being overrided by parent template.included template blocks are not being overridden by parent template.

comment:24 by Aymeric Augustin, 10 years ago

Resolution: wontfix
Status: newclosed

The design decision on ticket 12008 states that blocks are evaluated before includes.

As a consequence, the behavior should not be changed here.

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