[Zope] Re: Java re-invents DTML :-)

Max M maxm@mxm.dk
Mon, 24 Feb 2003 14:21:52 +0100


Terry Hancock wrote:

 >I think the real distinction between ZPT and DTML partisans is what it is
 >they spend most of their time doing, and how they think about the 
resulting
 >applications:  If you are using a basically static site design, which is
 >simply a front-end to a python application, ZPT may be great -- and if it
 >solves your organizational problem, very much so.  But if your site is
 >basically generative -- being itself restructured by the output of a 
python
 >application, and not a mere vessel for it, then DTML is awfully handy.


I completely disagree with that!


Doing sites with completely non-redundant design code is *much* simpler 
in zpt than in dtml.

I strongly suspect that those who hang on to dtml either have a lot of 
redundant layout-code, or use some terrible time-consuming methods to 
make dtml "behave"

Here's a simple example of what I mean:

If I have a layout element that is re-used on several pages, like a 
"slashbox", it could have the following html code:


<!-- lay_box -->
<table>
    <tr>
        <th>
            Some title
        </th>
    </tr>
    <tr>
        <td>
            This is some content ...
        </td>
    </tr>
</table>


Many designers will then just copy paste this code all over a site. 
Having disasterous effects when the time comes to change the layout. It 
can be expressed in dtml like this:


<!-- lay_box -->
<table>
    <tr>
        <th>
            <dtml-var boxTitle>
        </th>
    </tr>
    <tr>
        <td>
            <dtml-var boxContent>
        </td>
    </tr>
</table>


To call this dtml method from dtml you would use something like:

<dtml-var lay_box(boxTitle='Some title',
                  boxContent='This is some content ...')>

But the problem here is that you need some very complicated python/dtml 
code to populate the box with content that is just a little more 
complicated than that.

This offsets the time saved by re-using the code.


In zpt on the other hand it is so easy to do it right. You just define a 
metal macro with your re-usable design element:


<table metal:define-macro="box">
    <tr>
        <th>
            <span metal:define-slot="title">title</span>
        </th>
    </tr>
    <tr>
        <td>
            <div metal:define-slot="content">content</div>
        </td>
    </tr>
</table>


It can then be called from any zpt page in a very flexible manner.

<div metal:use-macro="container/lay_box/macros/box">
    <span metal:fill-slot="title">UV elementer</span>
    <div metal:fill-slot="content">
        This is some content ... that can be very flexible ...
    </div>
</div>


Here you also call the zpt "function" with 2 parameters. The big 
difference is that the 2 parameters can be complex layout themself. 
Which is exactly the right aproach for a layout language.

Metal really is what makes the big difference between dtml and zpt.

And if you find that it isn't enough reason to switch, you have not 
understood the magnitude of the problem it solves!!!


regards Max M