I'm trying to use a simple_tag and set a context variable. I'm using the trunk version of django:
from django import template
@register.simple_tag(takes_context=True)
def somefunction(context, obj):
return set_context_vars(obj)
class set_context_vars(template.Node):
def __init__(self, obj):
self.object = obj
def render(self, context):
context['var'] = 'somevar'
return ''
This doesn't set the variable, but if I do something very similar with @register.tag
it works but the object parameter doesn't pass through...
Thanks!
You are mixing two approaches here. A
simple_tag
is merely a helper function, which cuts down on some boilerplate code and is supposed to return a string. To set context variables, you need (at least with plain django) to write your own tag with a render method.This may be called like this: