[Zope] Page Template --> tal:repeat

"Echeverria Rabi, Cristián" cecheverria@transelec.cl
Fri, 26 Jul 2002 10:14:36 -0400


Thanks for your help.
Thanks to yours suggestions I solved my current problem.

I've something like this:

1. A main page template that get the values and call a Python Script
2. A Python Script that query a database (calling another script). Then I
have the result of the query in a variable. Then my script call another page
template to do the rendering of the result.
3. A page template to render the results of the query (so I need to pass the
variable with the result of the query).

All yours suggestion worked, but I needed to include a line in my script
before calling the final page template:

contest.REQUEST.set('value',query_result)

... and then everything worked.

I'm not sure this is the right way to do it, I'm just starting with zope,
Any other comments?

Thanks
Cristian

-----Original Message-----
From: Joel Burton [mailto:joel@joelburton.com] 
Sent: Friday, July 26, 2002 9:15 AM
To: Chris Meyers; Echeverria Rabi@joelburton.com; Cristián; zope@zope.org
Subject: RE: [Zope] Page Template --> tal:repeat

> -----Original Message-----
> From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of =
Chris
> Meyers
> Sent: Thursday, July 25, 2002 2:14 PM
> To: Echeverria Rabi; Cristián; zope@zope.org
> Subject: Re: [Zope] Page Template --> tal:repeat
>
>
> On Thu, Jul 25, 2002 at 01:09:40PM -0400, "Echeverria Rabi,
> Cristián" wrote:
> > I need to do something like this
> >
> > <tr tal:repeat="row python:range(value)">
> >
> > But value come from another template with a form.
> > I always have the same error:
> >
> > Error Type: TALESError
> > Error Value: exceptions.NameError on global name 'value' is not
> defined in
> > '', at line 14, column 5
> >
> > I don't know how to solve this. I want to iterate over a
> sequence produced
> > by a python script, but I can't pass an argument to the script that =
came
> > from a form in another page.
> >
> > Thanks for any help
> > Cristian
>
> Assuming that value is part of the request namespace you could do
> something like:
> <tr tal:define="value reques/value" tal:repeat="row =
python:range(value)">

Minor typo there: that's

<tr tal:define="value request/value" tal:repeat="row python:range(value)">

                            ^

or you can do it all at once, as

<tr tal:repeat="row python: range(request.value)">

or, to *make sure* that the value comes from the form variables passed by
your last script (as opposed to coming from some other place in the request
variable):

<tr tal:repeat="row python: range(request.form['value'])">