[TransWarp] Template parsing and XML/HTML processing design

Jean Jordaan jean at upfrontsystems.co.za
Mon Jul 21 08:11:43 EDT 2003


> you can go overboard with ZPT's "python:" expressions 

You can also abuse PEAK-style templating by wilfully moving all 
the UI back into Python, so that your template ends up simply::

  <h1 model="allthedata" view="thewholepage">
    Too bad, DreamWeaver Jockey!
  </h1>

I like this kind of ZPT very much::

  <table>
  <tr tal:repeat="item here/tabulardata">
    <td tal:condition="repeat/item/even"
        tal:content="item" class="evenrow">
      Even row</td>
    <td tal:condition="repeat/item/odd" 
        tal:content="item" class="oddrow">
      Odd row</td>
  </tr>
  <tr tal:replace="nothing>
    <td class="evenrow">Sample data, as much as needed</td>
  </tr>
  <tr tal:replace="nothing>
    <td class="oddrow"> for a realistic mockup.</td>
  </tr>
  </table>

This way, not only is my UI fully documented in the template
(I don't have to look in a tag factory for what will be sent
to the browser), the UI designer can redesign:

  <tal:contents repeat="item here/tabulardata">
    <div tal:condition="repeat/item/even"
        tal:content="item" class="evenrow">
        Even row</td>
    <div tal:condition="repeat/item/odd" 
        tal:content="item" class="oddrow">
        Odd row</td>
    <div tal:replace="nothing
         class="evenrow">Sample data, as much as needed</td>
    </div>
    <div tal:replace="nothing
         class="oddrow"> for a realistic mockup.</td>
    </div>
  </tal:contents>

to a CSS-based site, without the code needing to be touched.

Of course, to manage this consistently needs discipline and
shared use patterns. Perhaps it can be encouraged by limitations
on ZPT (eschew python: and structure:), but to make it impossible
isn't great either.

-- 
Jean Jordaan
http://www.upfrontsystems.co.za




More information about the PEAK mailing list