[Zope] iteration
John Morton
John Morton <jwm@plain.co.nz>
Tue, 6 Mar 2001 17:34:35 +1300 (NZDT)
On Tue, 6 Mar 2001 00:48:00 -0300 Alex Verstraeten <alex@quad.com.ar> wrote=
:
> I'm trying to port a very small portion of a php script i used to have.
> the concept is quite easy, but I dont see how to accomplish it at zope.
>=20
> let' see if anyone can understand this php code and tell me which functio=
n
> at zope may I use for it:
>=20
> print "<table>";
> print "<tr>";
> while ($item =3D current($array))
> {
> for ($n=3D0 ;$n<3;$n++)
> {
> print "<td>$item</td>";
> next($array);
> }
> print "</tr>";
> }
> print "</table>";
>=20
> what this code does is to print all the contents of an array in a table o=
f 3
> columns, using a cell for each element. I'm trying to do this same thing =
but
> using a <dtml-in expr=3D"objectValues('Folder')"> instead of the array.
>=20
> Can someone provide a dtml sample on how to do this?
I'd do it as a PythonMethod or PythonScript:
output =3D '<table>\n'
column =3D 1
for item in array:
if column =3D=3D 1:
output =3D output + '<tr>\n'
output =3D output + '<td>%s</td>\n' % item
if column =3D=3D max_column:
output =3D output + '</tr>\n'
column =3D 1:
else:
column =3D column + 1
output =3D output + '</table>\n'
return output
This code is written off the top of my head, so I don't know if it works.
I do know that it won't do too well when the number of elements in the
array isn't a muliple of max_column; I'll leave that as an exercise for
the reader :-)
John
=20