Hi All,
I'm using the code from
http://www.soyoucode.com/2011/set-variable-django-template
from django import template
register = template.Library()
class SetVarNode(template.Node):
def __init__(self, var_name, var_value):
self.var_name = var_name
self.var_value = var_value
def render(self, context):
try:
value = template.Variable(self.var_value).resolve(context)
except template.VariableDoesNotExist:
value = ""
context[self.var_name] = value
return u""
def set_var(parser, token):
"""
{% set <var_name> = <var_value> %}
"""
parts = token.split_contents()
if len(parts) < 4:
raise template.TemplateSyntaxError("'set' tag must be of the
form: {% set <var_name> = <var_value> %}")
return SetVarNode(parts[1], parts[3])
register.tag('set', set_var)
I've my main template base.html and in this I include config.html
where I load up the above custom templatetag set_var
{% load set_var %}
{% set iconsize = 50 %}
I then include another template file from base.html which would like
to make use of the variable I've assigned in the config.html
Now I can assign the variable in config.html and it works fine in this
context. I'm stuck with how to make it global though. Any help would
be appreciated. I'm new to python / django and I've been tearing my
hair out trying to figure out how to go about doing this.
Any help would be greatly appreciated
James
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.