[ZPT] Making TAL span across XHTML tags (long)

Geir Bækholt Geir Bækholt <geirh@funcom.com>
Fri, 20 Apr 2001 10:42:37 +0200


you could try using <tbody> </tbody> around your groups of table
rows..

It is only a soution for tables, though , and not a general fix , but
most places outside a table you could easily use a div..

i was in doubt about the validity of using multiple <tbody>elements in
 a table , but the w3 validador does not complain in a html4 document
 at least..

 :-)

--
Geir Bækholt
web-developer/designer
geirh@funcom.com
http://www.funcom.com

on or about, Friday, April 20, 2001, we have reason to believe that Butch Landingin wrote something along the lines of :
BL> Hi, 

BL> I've just begun playing with ZPT & TAL recently and only 
BL> today did become aware that there was a separate ZPT list so 
BL> I guess this is the right forum to ask...

BL> My approach with ZPT has been to take existing HTML pages 
BL> and adapt them to work with ZPT, Pythonscripts and/or Python 
BL> code  -- while this approach may not be the most ideal, it 
BL> has given me some insights as to what problems I may encounter 
BL> once I try to use ZPT in a production environment...

BL> One of the biggest limitations I've encountered so far is the
BL> fact that TAL expressions(specifically loop and condition) 
BL> can't span across tags (node?) -- (this isn't the clearest 
BL> statement of my problem, it may be better to show an example):

BL> Lets say that I have tal loop iterating over a list of articles
BL> (and assuming that these are implemented via pythonscripts/python
BL> functions):
BL>    ...
BL>    <table>
BL>    <tr tal:loop="article python: article_list()" >
BL>         <td tal:content="python: article.title()"> 
BL>                 Sample Article Title 1
BL>         </td>
BL>         <td tal:content="python: article.body()"> 
BL>                 Sample Article 1 blah blah blah
BL>         </td>
BL>    </tr>
BL>    <!-- the following row is repeated several times in the template to 
BL>            render nicely (and realistically) on an html editor.
BL>            I've removed them for brevity as I write it in this
BL>            example
BL>     -->
BL>    <tr tal:replace="nothing"  > 
BL>        <td>
BL>                 Sample Article 2 Title
BL>        </td>
BL>        <td>
BL>                 Sample Article 2 body blah blah blah 
BL>        </td>
BL>    </tr> 
BL>    </table> 
BL>    ...

BL> This is fine so far (I told you this will be a long message ;^))
BL> However, if I want each iteration (i.e. loop over each article) 
BL> to generate two rows so that it produces something like this:

BL> <table>
BL>   <tr class="article_title"> 
BL>      <td>
BL>          Article 1 title 
BL>      </td>
BL>   </tr>
BL>   <tr class="article_body"> 
BL>      <td>
BL>          Article 1 body blah blah 
BL>      </td>
BL>   </tr>
BL>   <tr class="article_title"> 
BL>      <td>
BL>         Article 2 title 
BL>      </td>
BL>   </tr>
BL>   <tr class="article_body"> 
BL>      <td>
BL>         Article 2 body blah blah 
BL>      </td>
BL>   </tr>
BL> </table>

BL> I'm at a loss as to how to create a simple (and straight-forward) 
BL> ZPT template (no weird hacks please) that will take the original
BL> html document, allow me to add some TAL tags (and some nifty python
BL> programming) and create a dynamic page from it.

BL> What I've done is a work-around that seems to work (at least for IE
BL> & Mozilla) for the HTML editor I'm using (HomeSite)
BL> where I insert a span tag to cover the 2 tr tags:
 
BL>    <table>
BL>    <span tal:loop="article python: article_list()" >
BL>    <tr>
BL>         <td tal:content="python: article.title()"> 
BL>                 Sample Article Title 1
BL>         </td>
BL>     </tr>
BL>     <tr>
BL>         <td tal:content="python: article.body()"> 
BL>                 blah blah blah
BL>         </td>
BL>    </tr>
BL>    </span>
BL>    <!-- same as before, except it reflects the first 2 rows as above -->
BL>    <tr tal:replace="nothing"  > 
BL>        <td>Sample Article 2 Title</td>
BL>    </tr>
BL>    <tr tal:replace="nothing"  > 
BL>        <td> Sample Article  2 body blah blah blah </td>
BL>    </tr> 
BL>    </table>
BL>    ...

BL> While this works for me ... it does have its own set of problems:
BL> It may be just a an accident (or bug) that IE/Mozilla or my HTML 
BL> editor ignores the span tag inside the table when rendering the page 
BL> -- but its not really valid HTML or XHTML... other editors/browsers
BL> may in the future cause problems (especially validators -- HTML tidy
BL> already complains about it).
  
BL> Are there better solutions to fix this problem? Or if not, are
BL> there extensions to TAL that can fix this? I've noticed this problem
BL> primarily affects the "condition" and "loop" TAL expressions in places
BL> where I can't use the span/div tag (such as in tables).
 
BL> Something like a TAL "block specification" may be the cure --  a way to
BL> specify that the TAL loop/condition expression spans more than one node 
BL> (I'm thinking in terms of HTMLDOM nodes).

BL> I dunno if the work (or additional complication in TAL syntax)
BL> involved in implementing this would be  worth it for the problem its trying 
BL> to solve(its just that the example I've shown is a pretty common technique to
BL> present stuff) -- so I'm just throwing this out to the people implementing ZPT  
BL> so maybe they  can think about it? 

BL> Regards,

BL> Butch



BL> __________________________________________________
BL> Do You Yahoo!?
BL> Yahoo! Auctions - buy the things you want at great prices
BL> http://auctions.yahoo.com/

BL> _______________________________________________
BL> ZPT mailing list
BL> ZPT@zope.org
BL> http://lists.zope.org/mailman/listinfo/zpt