Code

Opened 5 years ago

Closed 3 years ago

#11989 closed New feature (fixed)

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

Reported by: jdunck Owned by: nobody
Component: Template system Version: 1.1
Severity: Normal Keywords:
Cc: danielquinn 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 jdunck 5 years ago.
inclusion_template2.diff (7.4 KB) - added by tcoenen 3 years ago.
Updated patch now includes tests and documentation as well.

Download all attachments as: .zip

Change History (8)

Changed 5 years ago by jdunck

comment:1 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 3 years ago by julien

  • Easy pickings set
  • Severity set to Normal
  • Type set to 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 3 years ago by julien

  • Has patch set

Changed 3 years ago by tcoenen

Updated patch now includes tests and documentation as well.

comment:4 Changed 3 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 3 years ago by danielquinn

  • Cc danielquinn added
  • Triage Stage changed from Accepted to Ready 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 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16374]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.