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> ### END CODE ### I'm from a PHP/Perl/mySQL/postgreSQL background and am new to OOP, Python and Zope so I greatly appreciate any assistance with this. Regards, Tom
+-------[ Tom_Rectenwald@carmax.com ]---------------------- | | Hello all, [snip] | 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? Probably millions of ways... here's one. | | ### 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> Replace this; | <td tal:condition="python: transfer.server==''"> </td> | <td tal:condition="python: transfer.server!=''" | tal:content="structure transfer/server">server</td> With this; <tal:block define="theContent python:test(transfer.server, transfer.server,' '"> <td tal:content="structure theContent"></td> </tal:block> | </tr> | </table> | | ### END CODE ### -- Andrew Milton akm@theinternet.com.au
On 07.Dec 2004 - 09:21:01, Tom_Rectenwald@carmax.com wrote:
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?
AFAIK no, there is no "else" in tal:condition, but you should be able to use SQL to add a " " wherever there is an empty string in that column. Andreas -- Your reasoning powers are good, and you are a fairly good planner.
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>
You can just do: <td tal:content="structure python:transfer.server or ' '">server</td> Florent -- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
On Tue, Dec 07, 2004 at 03:50:12PM +0100, Florent Guillaume wrote:
You can just do:
<td tal:content="structure python:transfer.server or ' '">server</td>
yes. But I'd rather do it like: <td tal:content="structure python:transfer.server or default"> </td> -- Paul Winkler http://www.slinkp.com
zope-bounces@zope.org wrote on 12/07/2004 10:15:50 AM:
On Tue, Dec 07, 2004 at 03:50:12PM +0100, Florent Guillaume wrote:
You can just do:
<td tal:content="structure python:transfer.server or ' '">server</td>
yes. But I'd rather do it like:
<td tal:content="structure python:transfer.server or default"> </td>
--
Paul Winkler http://www.slinkp.com _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Thanks all for the many different ways to do this. It has really opened my eyes to the potential of TAL and Zope. I will use: <td tal:content="structure python:transfer.server or default"> </td> as that seems to be the clearest way of doing this; however, I am reviewing all of the other options to learn from this as well. Thanks again!
wrote:
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>
### END CODE ###
Try this: <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:content="structure python: transfer.server or default" > </td> </tr> </table> When transfer.server is false (e.g. None or an empty string), this uses the default value i.e. , if transfer.server is any value which is considered true it substitutes the value. For a more complex condition you could use the 'test' function: <td tal:content="structure python:test(transfer.server=='', default, transfer.server)" > </td> This would use the default only for an empty string, not for other false values such as False or None.
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
participants (7)
-
Andreas Pakulat -
Andrew Milton -
Duncan Booth -
Florent Guillaume -
Paul Winkler -
Tino Wildenhain -
Tom_Rectenwald@carmax.com