[Zope] Re: Output only the first or a particular record using TAL
Tres Seaver
tseaver at palladion.com
Wed Sep 14 07:33:23 EDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Julian Yap wrote:
> Hi all,
>
> I wanted to create something of a header using TAL and a Z SQL Method.
>
> I have the following code where getCustomerLicenses is my Z SQL Method and
> it prints out the customer's full name with details:
> <tr tal:repeat="licenses container/getCustomerLicences">
> <td><span tal:replace="licenses/full_name">full_name</span></td>
> <td><span tal:replace="licenses/serial_number">serial_number</span></td>
> <!-- code continues with more details -->
> </tr>
>
> In it's simplest form, how do I retrieve just the full_name of the first
> record using TAL. I think I use tal:replace but I'm not sure.
>
> I was along the lines of something like this:
> <tr tal:define="x container/getCustomerLicences">
> <td tal:replace="x/full_name[0]></td>
> </tr>
>
> But then I just get a TypeError.
You need to access the first record before asking for its attributes.
Also, path expressions don't play nicely with integer indexes, so you
need to use Python:
<td tal:content="python: x[0]['full_name']" />
You can use 'tal:condition repeat/licenses/start' to test that you are
in the first pass through the loop.
Tres.
- --
===================================================================
Tres Seaver +1 202-558-7113 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDKAqD+gerLs4ltQ4RAhKEAJsFo4Tm2DLiUTCSEjcqDUxgVvfsrQCffiyP
hXXtC8lu3xbW20JY0RVXOyg=
=j0u0
-----END PGP SIGNATURE-----
More information about the Zope
mailing list