[ZPT] repeat trick

Matthew Almond malmond@bw.edu
Tue, 10 Jul 2001 10:54:09 -0400


Terse but hopefully useful response:

tal:define="users here/getUsers | nothing; string modules/string"
tal:content="python:test(users ==
None,lambda:'',lambda:string.join(users,'\n'))()"

Where:

test(condition,lambda:trueexp,lambda:falseexp)()

===

if condition:
	result = trueexp
else:
	result = falseexp

Cunning no? :)

I've not actually tested this, but I've used something extremely similar
elsewhere.

Matthew Almond

-----Original Message-----
From: Peter Bengtsson [mailto:mail@peterbe.com]
Sent: Tuesday, July 10, 2001 10:33 AM
To: zpt@zope.org
Subject: [ZPT] repeat trick


Please have a look at
http://www.zope.org/Members/peterbe/DTML2ZPT/#example13

This is the code I'm having problems with::

 <textarea name="users:list"
    tal:define="users here/getUsers | nothing; string modules/string"
    tal:content="python:string.join(users,'\n')"></textarea>

First is defines what 'users' is by that function, and if not found, it's
defined as 'nothing'.
This is wrong because 'nothing' can't be looped over.
What I theoretically wanted to do was this:

  tal:define="users here/getUsers | []"

but that's not permitted.

How to do?

Cheers, Peter


_______________________________________________
ZPT mailing list
ZPT@zope.org
http://lists.zope.org/mailman/listinfo/zpt