Opened 9 years ago

Closed 5 years ago

Last modified 5 years ago

#6506 closed Bug (fixed)

simple include tag doesn't layer context like normal include tag

Reported by: kcarnold 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 kcarnold 9 years ago.

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by kcarnold

comment:1 Changed 9 years ago by mattmcc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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

comment:2 Changed 9 years ago by kcarnold

  • Resolution invalid deleted
  • Status changed from closed to 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 %}{% 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 8 years ago by jacob

  • Triage Stage changed from Unreviewed to Design decision needed

comment:4 Changed 8 years ago by kcarnold

  • Cc kenneth.arnold@… added

comment:5 Changed 5 years ago by julien

  • Resolution set to fixed
  • Severity set to Normal
  • Status changed from reopened to closed
  • Type set to Uncategorized

This has been fixed in #14987.

comment:6 Changed 5 years ago by SmileyChris

  • Type changed from Uncategorized to Bug
Note: See TracTickets for help on using tickets.
Back to Top