[ZPT] Re: TALESPropertySheet or using TALES as a propertydefinition
Evan Simpson
evan@zope.com
Wed, 08 Aug 2001 11:41:28 -0400
Ulrich Eck wrote:
> there is some info in the ZPT-Wiki about your vision a new kind of
> PropertySheet .. do you have any examples avaliable or are this
> just thoughts.
Just thoughts, I'm afraid.
> I want to be able to define Properties in TALES.
>
> e.g. id: "mytitle", value: "python:here.title_or_id()"
Sorry this response took so long. Here's a sample session that may help
(I'm CCing to ZPT in case this may help others):
>>> from Products.PageTemplates.Expressions import getEngine
>>> e = getEngine()
>>> expr = e.compile('python:x+1')
>>> c = e.getContext({'x': 1})
>>> c.evaluate(expr)
2
>>> c.evaluateText(expr)
'2'
>>> c.evaluateBoolean(expr)
1
>>> c.beginScope()
>>> c.setLocal('x', 5)
>>> c.evaluateText(expr)
'6'
>>> c.endScope()
>>> c.evaluateText(expr)
'2'
>>> # The following is less efficient, but more direct:
>>> c.evaluateText('string:$x!')
'2!'
The dictionary that you pass to getContext() defines builtin variables.
If you want to detect a return value of 'default', compare the value
to c.getDefault(). The TALES exception is c.getTALESError().
Cheers,
Evan @ Zope