Opened 15 years ago

Closed 12 years ago

#7438 closed New feature (duplicate)

Add keyword support to simple_tag and inclusion_tag

Reported by: dougn Owned by: nobody
Component: Template system Version: dev
Severity: Normal Keywords: keywords inclusion_tag simple_tag tags
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


for a project I found it very useful to support named keyword args on simple and inclusion tags.


def mytag(a, b=None, c=None):
    return {}

def inctag(data, **kwdargs):
    return kwdargs
{% mytag c="hello" a=3 %}
{% inctag var1=3 user=user foo="bar" %}

<!-- just a few of the errors detected as proper template errors -->
{% mytag c=5 %} <!-- template error! "%s takes at least %s non-keyword arguments (%s given)" -->
{% mytag 1 bad=4 %} <!-- template error! %s got an unexpected keyword argument '%s' -->
{% mytag 1 c=3 c=4 %} <!-- template error! %s got multiple values for keyword argument '%s' -->

contains complete error
Including a patch for this, sans the unit tests. jezdez will help with that.

Attachments (1)

kwdarg_template_tag.patch (6.4 KB) - added by dougn 15 years ago.
initial patch with full support (but no unit tests)

Download all attachments as: .zip

Change History (7)

Changed 15 years ago by dougn

Attachment: kwdarg_template_tag.patch added

initial patch with full support (but no unit tests)

comment:1 Changed 15 years ago by eopadoan

FWIW, I had to wrap {% include %} tags with {% with %} tags sometimes, so I can see many use cases for the inclusion tag.

comment:2 Changed 15 years ago by Matt McClanahan

Has patch: set
Needs tests: set
Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 12 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:4 Changed 12 years ago by Jacob

Easy pickings: unset
Triage Stage: Design decision neededAccepted
UI/UX: unset

comment:5 Changed 12 years ago by Jacob

Since we've standardized on this "=" syntax is seems to make sense for the simple tags to support this, too.

comment:6 Changed 12 years ago by Julien Phalip

Resolution: duplicate
Status: newclosed

Closing as dupe of #13956, which as a patch that's pretty much ready to go.

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