[TransWarp] Template parsing and XML/HTML processing design

Phillip J. Eby pje at telecommunity.com
Mon Jul 21 09:43:22 EDT 2003


At 02:11 PM 7/21/03 +0200, Jean Jordaan wrote:
>>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>

Of course; but that would be silly.


>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>

<table xmlns:pt="http://peak.telecommunity.com/peak.web.templates/" 
pt:model="tabulardata" pt:view="list">
<tr pt:pattern="listItem">
    <td class="oddrow" pt:view="text">Odd row</td>
</tr>
<tr pt:pattern="listItem">
    <td class="evenrow" pt:view="text">Even row</td>
</tr>
<tr>
    <td class="oddrow">Sample data, as much as needed</td>
</tr>
<tr>
    <td class="evenrow">for a realistic mockup.</td>
</tr>
</table>

Using "listItem" more than once causes the "list" view to rotate through 
the patterns.  Of course, I have to put the odd row first.  The "list" and 
"text" views also drop any content within them that isn't part of a 
pattern, so you don't have to add any special markup to sample data 
contained within them.



>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.

I'll leave the translation to PWT as an exercise for the reader.  ;)


>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.

I'm not sure what it is you're saying is impossible.  PWT makes possible a 
lot of things that are highly impractical in other templating systems; it's 
roughly a cross between the respective powers of Woven (model/view/pattern 
concept) and PSO/JSP (tags become custom object instances at "compile time").

By the way, nobody is saying you can't use other templating systems with 
peak.web.  Ulrich Eck, for example, created a demo ZPT binding for peak.web 
last week.  I won't be including it in PEAK because it's not particularly 
robust on either side of the binding at the moment.  But if somebody did 
contribute a robust binding with tests, I'd consider including it -- just 
not until there are enough view components available for PWT to look more 
attractive by comparison.  :)




More information about the PEAK mailing list