#6506 closed Bug (fixed)
simple include tag doesn't layer context like normal include tag
Reported by: | Kenneth Arnold | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | include custom tag library context layer inherit |
Cc: | kenneth.arnold@… | Triage Stage: | Design decision needed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This was surprising behavior: unlike the provided include tag, user-defined include tags don't layer the provided context on top of the existing context.
It is consistent with a strict reading of the docs, but it's a confusing and un-motivated difference from ordinary include behavior.
I'm attaching a quick and dirty patch to fix this. The needed design decision is exactly how the context class should be handled; is there a use case for something other than just Context? (RequestContext needs another parameter...)
Attachments (1)
Change History (7)
by , 17 years ago
Attachment: | django-layer-context-in-include-tag.patch added |
---|
comment:1 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Point. (Yes I knew about that, but I didn't see the use case.)
Suggest adding to the docs something like: "You can replace
{% with id=thing.id %}{% include "other.html" %}{% endwith %}
with a custom tag:
@register.simple_tag('other.html', takes_context=True) def other(context, id): context[id] = id return context
and simpler code:
{% other thing.id %}
Alternatively, make the previous proposed behavior the default if context_class
is not provided, with the meaning "If I provide my own context class, I want to control how context handling happens. Otherwise, do it the way I'm used to include
tags doing it.".
comment:3 by , 17 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:4 by , 16 years ago
Cc: | added |
---|
comment:5 by , 14 years ago
Resolution: | → fixed |
---|---|
Severity: | → Normal |
Status: | reopened → closed |
Type: | → Uncategorized |
This has been fixed in #14987.
comment:6 by , 14 years ago
Type: | Uncategorized → Bug |
---|
Inclusion tags can receive the template context. See 'takes_context'. http://www.djangoproject.com/documentation/templates_python/#inclusion-tags