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

Michael Dudzik mdudzikml at gmail.com
Wed Feb 1 13:11:58 EST 2006


On Wed, 01 Feb 2006 09:07:17 +0100, "Andreas Jung"
<lists at andreas-jung.com> said:
> 
> 
> --On 1. Februar 2006 09:04:36 +0100 Frank Burkhardt <fbo2 at gmx.net> wrote:
> 
> > Hi,
> >
> > 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

However, the expression (B,A)[C] always works if C is a boolean

I'm using that until Python 2.5 comes along.



More information about the Zope3-users mailing list