1 from django import template
2
3 register = template.Library()
4
6
8 self.var_name = var_name
9 self.var_value = var_value
10
12 try:
13 value = template.Variable(self.var_value).resolve(context)
14 except template.VariableDoesNotExist:
15 value = ""
16 context[self.var_name] = value
17 return u""
18
20 """
21 {% set <var_name> = <var_value> %}
22 """
23 parts = token.split_contents()
24 if len(parts) < 4:
25 raise template.TemplateSyntaxError("'set' tag must be of the form: {% set <var_name> = <var_value> %}")
26 return SetVarNode(parts[1], parts[3])
27
28 register.tag('set', set_var)
29