This is a call to review ticket #1105. The proposed patch is fully
functional, backwards-compatible and contains tests and documentation.
http://code.djangoproject.com/ticket/1105
Currently it is not possible to access the context from within a
simple_tag, and there is no "simple" way to create block tags. Both of
these tasks imply using some boilerplate code to parse the tokens,
manage variables, etc.
The patch in #1105 addresses these two issues. What you can now do:
1) Get access to the context:
@register.simple_tag(takes_context=True)
def mytag(context, arg1, arg2):
...
2) Easily create simple block tags:
@register.simple_tag(takes_nodelist=True)
def mytag(nodelist, arg1, arg2):
...
{% mytag some_var "some_string" %}
...
{% endmytag %}
3) Or even do both:
@register.simple_tag(takes_context=True, takes_nodelist=True)
def mytag(context, nodelist, arg1, arg2):
...
These enhancements should make the development of simple template tags
much faster. The patch's tests also make sure that it remains
backwards-compatible and won't break existing code. I've added this to
the Version 1.1 feature wish-list.
Any feedback welcome, thanks!
Julien :)