Opened 7 years ago

Closed 5 years ago

#11989 closed New feature (fixed)

Allow @register.inclusion_tag to take a template as well as a template name

Reported by: Jeremy Dunck Owned by: nobody
Component: Template system Version: 1.1
Severity: Normal Keywords:
Cc: Daniel Quinn Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Sometimes, I want the convenience of an inclusion_tag without specifying an external template. I can't use simple_tag because I need context access.

@inclusion_tag allows either a template name or an iterable of template names.

The attach patch allows a template to be given directly, as well.

I noticed @inclusion_tag doesn't seem to be currently tested, and this patch doesn't include tests. Where should @inclusion_tag tests live?

Attachments (2)

inclusion_template.diff (808 bytes) - added by Jeremy Dunck 7 years ago.
inclusion_template2.diff (7.4 KB) - added by tcoenen 6 years ago.
Updated patch now includes tests and documentation as well.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by Jeremy Dunck

Attachment: inclusion_template.diff added

comment:1 Changed 7 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Julien Phalip

Easy pickings: set
Severity: Normal
Type: New feature

Just noting that tests for inclusion_tag have recently been added to source:django/trunk/tests/regressiontests/templates/custom.py

comment:3 Changed 6 years ago by Julien Phalip

Has patch: set

Changed 6 years ago by tcoenen

Attachment: inclusion_template2.diff added

Updated patch now includes tests and documentation as well.

comment:4 Changed 6 years ago by tcoenen

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
UI/UX: unset

I updated the patch to apply to the current Django. The patch inclusion_template2.diff now includes documentation and tests for this new feature

comment:5 Changed 6 years ago by Daniel Quinn

Cc: Daniel Quinn added
Triage Stage: AcceptedReady for checkin

I applied his patch and it passed the tests and then checked out the result in the documentation. All looks good to me.

comment:6 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16374]:

Fixed #11989 -- Allow passing a Template instance to inclusion_tag. Thanks to Jeremy Dunck and tcoenen.

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