[ZPT] repeat trick

Matthew Almond malmond@bw.edu
Tue, 10 Jul 2001 12:51:13 -0400


Okay, I tried some of this out - neither my, or Evans seem to work (though
mine does work for another similar problem) - The problem is that test()
evaluates both the true and false part (as it's a function) and even if the
true part isn't used, it's evaluated.

I solved it by approaching the problem another way:

---begin test_zpt (Page Template)---
<form attributes="action here/absolute_url">
<textarea rows="5" cols="40" name="users:list"
          tal:content="here/getUsers"></textarea>
<input type="submit" value="OK">
</form>
---end---

---begin getUsers (Python Script)---
import string

if context.REQUEST.has_key('users'):
	return string.join(context.REQUEST['users'],'\n')
else:
	return ''
---end---

That works - it produces a simple textbox that 'keeps' it's value over form
submittals.
Oh, and I know the page's HTML sucks - it's just simplified for brevity :)

Matthew

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


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

Tried but returns Error Type: TALESError
Error Value: exceptions.NameError on users in ""

It's got to be doable in a simple fashion.

Peter