ZPT, a next-generation template technology

Hamish Lawson hamish_lawson at btinternet.com
Fri Mar 16 20:43:50 EST 2001


The Zope Presentation Templates project is underway at Digital Creations
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.
Developers from other communities may want 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 is meant by "next-generation".

In the beginning programmers wrote program code with embedded HTML. Then
technologies like eperl, ASP, PHP and JSP 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 in general 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 thus 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>

Because this doesn't make use of special tags, but employs attributes
instead, it should pass unscathed through most decent authoring tools.
Moreover (borrowing an idea from Enhydra's XMLC template scheme) the ZPT
template scheme allows typical sample content to be used as a proxy for
the real data (which is substituted by the template engine), so making
it easier to work with in an authoring tool.

More information on the rationale of attribute languages can be found

    http://dev.zope.org/Wikis/DevSite/Projects/ZPT/AttributeLanguage

An overview of ZPT can be found at

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


Hamish Lawson

* Zope is a leading open-source web application server and content-
management framework, written in Python by Digital Creations.







More information about the Python-list mailing list