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

Butch Landingin butchland@yahoo.com
Fri, 20 Apr 2001 01:24:09 -0700 (PDT)


Hi, 

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

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

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

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

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

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

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

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

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

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

Regards,

Butch



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