[Zope] Is it possible to render a TAL expression from a Page Template?

Alexis Roda alexis.roda.villalonga at gmail.com
Wed Jun 21 16:04:31 EDT 2006


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


More information about the Zope mailing list