Hi, Am Dienstag, den 07.12.2004, 09:21 -0500 schrieb Tom_Rectenwald@carmax.com:
Hello all,
I am a newbie at Zope, slowly traversing the learning curve. I am focusing on TAL currently, and am quite a bit confused with the tal:condition syntax. I have a Z SQL Method that selects all records from a table in a PostgreSQL database. This method is called "getTransfers". I then have a Page Template called "displayTransfers" that displays the results as tabular HTML.
This works fine. However, where there isn't a record (i.e. an empty string), a <TD> will not be defined so that it leaves ugly gaps in the table. To ensure that a '<TD> </TD>' replaces an empty string '' I added two tal:condition statements. This works, but is sort of ugly looking as, in my head, it is the equivalent of two 'if' statements when it should be an 'if/else'. The below code works, however is there a cleaner way to do this?
### START CODE ###
<table border="1"> <tr><th>Date</th><th>Server</th></tr> <tr tal:repeat="transfer container/getTransfers"> <td tal:content="structure transfer/time_stamp">time_stamp</td> <td tal:condition="python: transfer.server==''"> </td> <td tal:condition="python: transfer.server!=''" tal:content="structure transfer/server">server</td> </tr> </table>
Its more easy then you might think: There is no need to use tal:content here also I see no need to use structure. structure is used only if you have predefined html content you want to render. I doubt your timestamp is that kind of data. Even more if any data you display is originally user input, using structure would be a security hole. <tr tal:repeat="transfer container/getTransfers"> <td tal:content="transfer/timestamp">time_stamp</td> <td tal:content="transfer/server">server</td> </tr> is all you need. If your column is empty and contains only empty string, then you have <td></td> in the resulting HTML, which is fine. You can deal with CSS if you dont like the way certain browsers display such "empty" tags. Regards Tino