Opened 14 years ago
Closed 8 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 Changed 14 years ago by
comment:2 Changed 14 years ago by
Component: | Template system → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
Probably documentation needs to clarify this.
comment:3 Changed 14 years ago by
Description: | modified (diff) |
---|
comment:4 Changed 14 years ago by
Cc: | michael@… added |
---|
comment:5 Changed 14 years ago by
Related django-dev thread:
http://groups.google.com/group/django-developers/browse_thread/thread/796489b6f29440e4
comment:6 Changed 14 years ago by
Has patch: | set |
---|
comment:8 Changed 13 years ago by
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 Changed 13 years ago by
Owner: | changed from nobody to walpatal |
---|
I've been biten by this enough times to take a stab solving it.
Changed 13 years ago by
Attachment: | 6646.2.diff added |
---|
comment:10 Changed 13 years ago by
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 Changed 13 years ago by
a different but somewhat related feature is selective include tag #11832
comment:12 follow-up: 13 Changed 13 years ago by
Cc: | tom@… added |
---|
The patch is working for me. Any reason this is not in trunk yet?
comment:13 Changed 13 years ago by
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 Changed 13 years ago by
Owner: | walpatal deleted |
---|
comment:15 Changed 12 years ago by
Cc: | mmitar@… added |
---|
comment:16 Changed 12 years ago by
Cc: | drackett@… added |
---|
comment:17 Changed 11 years ago by
Type: | → Bug |
---|
comment:18 Changed 11 years ago by
Severity: | → Normal |
---|
comment:19 Changed 11 years ago by
Cc: | dueSouth added |
---|---|
Easy pickings: | unset |
UI/UX: | unset |
comment:20 Changed 11 years ago by
Cc: | botondus@… added |
---|
comment:21 Changed 11 years ago by
Cc: | dev@… added |
---|
comment:22 Changed 11 years ago by
Cc: | flisky added |
---|
comment:23 Changed 10 years ago by
Summary: | included template blocks are not being overrided by parent template. → included template blocks are not being overridden by parent template. |
---|
comment:24 Changed 8 years ago by
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.