Opened 7 years ago

Closed 4 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: master
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 7 years ago.
initial patch with full support (but no unit tests)

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by dougn

initial patch with full support (but no unit tests)

comment:1 Changed 7 years ago by eopadoan

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 7 years ago by mattmcc

  • Has patch set
  • Needs tests set
  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:4 Changed 4 years ago by jacob

  • Easy pickings unset
  • Triage Stage changed from Design decision needed to Accepted
  • UI/UX unset

comment:5 Changed 4 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 4 years ago by julien

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

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