Thanks for the encouragement, Alex.  This was so easy, it should be a
first lesson in how to write a custom tag.  It took about 15 minutes
and worked the first time!


from django import template

register = template.Library()

@register.tag(name="eval")
def do_eval(parser, token):
   try:
      tagName, variableName = token.split_contents()
   except ValueError:
      raise template.TemplateSyntaxError("%r requires a single
argument: the name of the variable to evaluate as the body of a
template" % tagName)

   return EvalNode(variableName)


class EvalNode(template.Node):

   def __init__(self, variableName):
      self.variableName = variableName


   def render(self, context):
      t = template.Template(context[self.variableName])
      return t.render(context)




On Jul 4, 5:51 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I don't think it would be difficult to implement, either as a block
> tag, or as a regular tag with context.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to