[Zope3-Users] test() in TALES in Zope3

Igor Stroh igor at rulim.de
Wed Feb 1 13:15:13 EST 2006


Michael Dudzik wrote:
> On Wed, 01 Feb 2006 09:07:17 +0100, "Andreas Jung"
[..]
>>>in Zope2 there's a test() method that can be used in TAL (*). Is there
>>>something comparable in Zope3?
>>>
>>>I know how to write such a method but how to make it available in the
>>>namespace of TALES-"python:"-expressions? I would like to write
>>>expressions like this:
>>>
>>><div tal:attributes="class python: 'foo' + test(condition == True,'
>>>bar','')" />
>>>
>>You can write this in Python as
>>
>>    condition and true_expression or false_expression
> 
> 
> That doesn't work under some conditions:
> 
> C and A or B where C is a boolean
> 
> if C is false it evaluates to B
> if C is true it evaluates to A EXCEPT when bool(A) == false
> 
> example:
> 
> C and None or 7 ALWAYS evaluates to 7

Just make it 'not C and 7 or None' :)

Igor


More information about the Zope3-users mailing list