Opened 16 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

Description

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

Example:

@register.simple_tag
def mytag(a, b=None, c=None):
    return {}

@register.inclusion_tag("example.html")
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 16 years ago.
initial patch with full support (but no unit tests)

Download all attachments as: .zip

Change History (7)

by dougn, 16 years ago

Attachment: kwdarg_template_tag.patch added

initial patch with full support (but no unit tests)

comment:1 by eopadoan, 16 years ago

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

comment:2 by Matt McClanahan, 16 years ago

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

comment:3 by Luke Plant, 13 years ago

Severity: Normal
Type: New feature

comment:4 by Jacob, 13 years ago

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

comment:5 by Jacob, 13 years ago

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

comment:6 by Julien Phalip, 12 years ago

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