Now that you have an eval tag, maybe you don't need this, but I think
Django already had a simpler solution to your problem:
Context:
buttonDecidedAtRunTime: 'button4.html'
thisPage: "/some/path"
blah.html:
<p>{% include buttonDecidedAtRunTime %}</p>
The argument to the include tag doesn't need to be a literal string, it
can be a value from the context. This has the added advantage that the
common "{% include " in each of your button choices is factored out and
appears only once, in blah.html.
--Ned.
http://nedbatchelder.com
Ben Kovitz wrote:
> 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 [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
-~----------~----~----~----~------~----~------~--~---