[Zope] Re: Output only the first or a particular record using TAL

Chris Withers chris at simplistix.co.uk
Fri Sep 23 16:53:40 EDT 2005


Julian Yap wrote:
> I used the following and it works great (without some formatting for
> clarity):
> <tr tal:define="customer container/getCustomerLicences"
> tal:condition="customer">
>     <td>Customer: <span
> tal:content="python:customer[0]['full_name']"></span></td>
> </tr>

hmm, this strikes me as just plain wrong :-S

Why is getCustomerLicenses returning more than one row if you only want 
the first one?

If it only returned one row, then you could do:

<tr tal:repeat="customer container/getCustomerLicences">
  <td>
   Customer:
   <span tal:content="customer/full_name"></span>
  </td>
</tr>

...no need for the condition or the yucky integer indexes.

Now, if you really can't stop your sql returning more than one row 
(LIMIT 1 anyone?) then how about:

<tr tal:define="customers container/getCustomerLicences;
                 customer  python:customers and customers[0]"
     tal:condition="customer">
  <td>
   Customer:
   <span tal:content="customer/full_name"></span>
  </td>
</tr>

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope mailing list