Opened 17 years ago

Closed 14 years ago

Last modified 14 years ago

#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)

django-layer-context-in-include-tag.patch (857 bytes ) - added by Kenneth Arnold 17 years ago.

Download all attachments as: .zip

Change History (7)

by Kenneth Arnold, 17 years ago

comment:1 by Matt McClanahan, 17 years ago

Resolution: invalid
Status: newclosed

Inclusion tags can receive the template context. See 'takes_context'. http://www.djangoproject.com/documentation/templates_python/#inclusion-tags

comment:2 by Kenneth Arnold, 17 years ago

Resolution: invalid
Status: closedreopened

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 Jacob, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:4 by Kenneth Arnold, 16 years ago

Cc: kenneth.arnold@… added

comment:5 by Julien Phalip, 14 years ago

Resolution: fixed
Severity: Normal
Status: reopenedclosed
Type: Uncategorized

This has been fixed in #14987.

comment:6 by Chris Beaven, 14 years ago

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