inelegant repetition of ZPT code
Hi Zopers Another detail that bugs me: how can I translate the following dtml code to zpt. It colours table rows in grey/white alternatively. Is the zpt version below the only way? It is clearly very inelegant to repeat code. DTML ... <table> <dtml-in listItems> <tr <dtml-if sequence-even>bgcolor="lightgray"</dtml-if>> <td>...</td> </tr> </dtml-in> </table> ZPT ... <table> <span tal:repeat="item here/listItems"> <tr bgcolor="white" tal:condition="repeat/item/even"> <td>...</td> </tr> <tr bgcolor="lightgray" tal:condition="repeat/item/odd"> <td>...</td> </tr> </span> </table> thanks and best wishes Andre
Andre Meyer wrote:
<table> <span tal:repeat="item here/listItems"> <tr bgcolor="white" tal:condition="repeat/item/even"> <td>...</td> </tr> <tr bgcolor="lightgray" tal:condition="repeat/item/odd"> <td>...</td> </tr> </span> </table>
use css, and python: <table> <tr tal:repeat="i here/listItems" tal:attribute="class python:path('repeat/i/odd') and 'shaded' or nothing"> <td>...</td> </tr> </table> -- Jamie Heilman http://audible.transient.net/~jamie/ "Most people wouldn't know music if it came up and bit them on the ass." -Frank Zappa
what's wrong with <untested> <tr tal:attributes="bgcolor python: test(repeat['item'].odd, 'white', 'lightgray'" /> </untested> -aj --On Dienstag, 25. November 2003 21:52 Uhr +0100 Andre Meyer <a.meyer@hccnet.nl> wrote:
Hi Zopers
Another detail that bugs me: how can I translate the following dtml code to zpt. It colours table rows in grey/white alternatively. Is the zpt version below the only way? It is clearly very inelegant to repeat code.
DTML
... <table> <dtml-in listItems> <tr <dtml-if sequence-even>bgcolor="lightgray"</dtml-if>> <td>...</td> </tr> </dtml-in> </table>
ZPT
... <table> <span tal:repeat="item here/listItems"> <tr bgcolor="white" tal:condition="repeat/item/even"> <td>...</td> </tr> <tr bgcolor="lightgray" tal:condition="repeat/item/odd"> <td>...</td> </tr> </span> </table>
thanks and best wishes Andre
_______________________________________________ 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 )
On Tue, Nov 25, 2003 at 10:02:37PM +0100, Andreas Jung wrote:
what's wrong with
<untested>
<tr tal:attributes="bgcolor python: test(repeat['item'].odd, 'white', 'lightgray'" />
</untested>
I believe the only thing wrong is that repeat['item'].odd may be a method, not an attribute, so your test as written would always be true. But I couldn't remember so I decided to use the path() function in my version rather than looking it up :-) -- Paul Winkler http://www.slinkp.com
On Tue, Nov 25, 2003 at 09:52:51PM +0100, Andre Meyer wrote:
Hi Zopers
Another detail that bugs me: how can I translate the following dtml code to zpt. It colours table rows in grey/white alternatively. Is the zpt version below the only way? It is clearly very inelegant to repeat code.
Maybe not the most elegant, but it avoids the repetition: <table> <span tal:repeat="item here/listItems"> <tr bgcolor="lightgray" tal:attributes="bgcolor python:path('repeat/item/odd') and 'white' or default"> <td>...</td> </tr> </span> </table> -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's GANGSTA MERRY MAN! (random hero from isometric.spaceninja.com)
participants (4)
-
Andre Meyer -
Andreas Jung -
Jamie Heilman -
Paul Winkler