Attached is a patch for a tag function decorator that I find useful. It's a simple extension of Robert's simple_tag. The tag function is passed the context as the first argument and also any arguments to the tag, resolved in the same way as for the simple_tag decorator. The decorated function can manipulate the context and either return a string, which will be inserted into the template, or None.
For example, this tag puts the project settings into the context:
@register.simple_tag_with_context
def get_settings(context):
"""
Put the project settings into the context.
Usage::
{% get_settings %}
"""
from django.conf import settings
context['settings'] = settings
And this one is the equivalent of the existing simple_tag example in NewAdminChanges:
@register.simple_tag_with_context
def monkey_tag(context, verb):
return "I %s no evil" % verb