[Zope] Is it possible to render a TAL expression from a
Page Template?
jpenny at ykksnap-america.com
jpenny at ykksnap-america.com
Wed Jun 21 16:33:04 EDT 2006
Thanks, the external method appears to work fine. I thought about the
silly Page Template, but forgot the path: modifier exists! But the EM
should be far faster, anyway.
Thanks again.
jim
zope-bounces at zope.org wrote on 06/21/2006 04:04:31 PM:
> En/na jpenny at ykksnap-america.com ha escrit:
> > Suppose I have a variable foo that has value "request/name|nothing".
> >
> > Is it possible from a Python Script to have this evaluated as a TAL
> > expression?
>
> AFAIK TALES machinery ($ZOPE_HOME/lib/python/Products/PageTemplates)
> can't be accessed from restricted code. Maybe ZTUtils,
> PythonScript.standard or other module expose it in some way, I don't
know.
>
> > Alternatives?
>
> * External method:
>
> from Products.PageTemplates.Expressions import getEngine
>
> def evalTAL(talstr, **kw) :
> engine = getEngine()
> comp = engine.compile(talstr)
> return engine.getContext(**kw).evaluate(comp)
>
> then, from a PythonScript do:
>
> result = context.evalTAL("request/name|nothing", here=context,
> request=REQUEST)
>
>
> * Create a PageTemplate named evalTAL with a body like:
>
> <foo tal:replace="python:path(options['param'])"></foo>
>
> then, from a PythonScript do:
>
> result = context.evalTAL(param="request/name|nothing")
>
> result will always be an string. Not a serious alternative, just a
> "creative" way.
>
>
>
>
> HTH
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
More information about the Zope
mailing list