Opened 9 years ago

Closed 6 years ago

Last modified 6 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: master
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: UI/UX:


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 9 years ago.

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by Kenneth Arnold

comment:1 Changed 9 years ago by Matt McClanahan

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: invalid
Status: newclosed

Inclusion tags can receive the template context. See 'takes_context'.

comment:2 Changed 9 years ago by Kenneth Arnold

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 %}{% 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 %}

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 Changed 9 years ago by Jacob

Triage Stage: UnreviewedDesign decision needed

comment:4 Changed 8 years ago by Kenneth Arnold

Cc: kenneth.arnold@… added

comment:5 Changed 6 years ago by Julien Phalip

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

This has been fixed in #14987.

comment:6 Changed 6 years ago by Chris Beaven

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