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 )
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)
Change History (26)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Component: | Template system → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
Probably documentation needs to clarify this.
comment:3 by , 17 years ago
Description: | modified (diff) |
---|
comment:4 by , 16 years ago
Cc: | added |
---|
comment:5 by , 16 years ago
Related django-dev thread:
http://groups.google.com/group/django-developers/browse_thread/thread/796489b6f29440e4
comment:6 by , 16 years ago
Has patch: | set |
---|
comment:8 by , 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 , 15 years ago
Owner: | changed from | to
---|
I've been biten by this enough times to take a stab solving it.
by , 15 years ago
Attachment: | 6646.2.diff added |
---|
comment:10 by , 15 years ago
Component: | Documentation → Template 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 , 15 years ago
a different but somewhat related feature is selective include tag #11832
follow-up: 13 comment:12 by , 15 years ago
Cc: | added |
---|
The patch is working for me. Any reason this is not in trunk yet?
comment:13 by , 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 , 15 years ago
Owner: | removed |
---|
comment:15 by , 14 years ago
Cc: | added |
---|
comment:16 by , 14 years ago
Cc: | added |
---|
comment:17 by , 14 years ago
Type: | → Bug |
---|
comment:18 by , 14 years ago
Severity: | → Normal |
---|
comment:19 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
UI/UX: | unset |
comment:20 by , 13 years ago
Cc: | added |
---|
comment:21 by , 13 years ago
Cc: | added |
---|
comment:22 by , 13 years ago
Cc: | added |
---|
comment:23 by , 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 , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The design decision on ticket 12008 states that blocks are evaluated before includes.
As a consequence, the behavior should not be changed here.
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.