[Zope] ZPT, a next-generation template technology

Hamish Lawson hamish_lawson@yahoo.co.uk
Sun, 11 Mar 2001 04:17:52 +0000 (GMT)


The Zope Presentation Templates project is underway to develop a
next-generation template technology for Zope* that is XHTML-compliant
and which makes it easier for designers to work with. However it is
hoped to design it in such a way that as much as possible is not
specific to Zope, in the belief that the technology is more widely
useful and could be adopted by other languages and tools. I'm extending
an invitation (in a personal capacity rather than as an official
spokesman for the project) to developers from other communities to
consider contributing to the design of ZPT to help keep it
language-independent, and to consider implementing the approach in
their programming language of choice.

First of all some background on what I mean by "next-generation".

In the beginning programmers wrote program code with embedded HTML.
Then technologies like eperl, ASP, JSP and PHP allowed us to reverse
this and to embed program code in the HTML. However a school of thought
wanted to have greater separation of presentation and logic, and so
various template mechanisms were devised that provided just enough
programmability to control presentation, but which moved the business
logic out elsewhere. One example of this approach is Freemarker:

   <h1>$customername</h1>
    <table border="1">
        <tr>
            <td>Date</td>
            <td>Amount</td>
        </tr>
        <list deposits as deposit>
            <tr>
                <td>${deposit.date}</td>
                <td>${deposit.amount}</td>
            </tr>
        </list>
    </table>

Instead of custom tags, some other template mechanisms use special
markers to designate control structures, but most template mechanisms
share the property that their templates are not compliant with XHTML
(though the rendered output may be). As such it can be awkward trying
to use such template mechanisms with authoring tools that only
understand XHTML.

The approach that the ZPT project is pursuing is to attach the
control-flow, formatting and placeholder directives as attributes of
standard XHTML tags. The example above becomes something like:

    <h1 zpt:insert="customername">Bob Smith</h1>
    <table border="1">
        <tr>
            <td>Date</td>
            <td>Amount</td>
        </tr>
        <tr zpt:repeat="deposit deposits">
            <td zpt:insert="deposit/date">01/02/2001</td>
            <td zpt:insert="deposit/amount">23.40</td>
        </tr>
    </table>

This is not only valid XHTML, but (borrowing an idea from Enhydra's
XMLC template scheme) the ZPT template scheme allows prototypical
content to be used as a proxy for the data to be substituted, so making
it easier to work with in an authoring tool.

An overview of the ZPT project can be found at

    http://www.zope.org/Wikis/DevSite/Projects/ZPT/VisionStatement

More information on ZPT's attribute language is at

    http://www.zope.org//Wikis/DevSite/Projects/ZPT/TAL


Hamish Lawson

* Zope is a leading open-source web application server and
content-management framework; it is written in Python.


____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie