Custom template tag args and kwargs parser
django, django-templates
Solution
I found a snippet that may be able to help you.
Tag that parses args and kwargs
Problem
Django ships with some great tools for making custom template tags. Register simple_tag and assignment_tag both parse the incoming token contents and convert them to `args, kwargs` correctly resolved to their references (say a variable was passed in). Is there a simple way to add this behavior to a regular tag? I need to use the `parser` object so I need to use a regular tag, but it seems like I'm wading through a lot of code to reproduce the `args, kwargs` parser. ``` @register.tag(name='snippet') def snippet_with_defaults(parser, token): bits = token.split_contents()[1:] bits # bits needs to be converted to args, kwargs easily ``` I need a tag that functions like this: ``` {% snippet foo=bar bar=baz %} This is a glorious django template tag! {% endsnippet %} ``` It seems like this is such a common issue (an args, kwargs parser for tag arguments) that it should have a django snippet or something!