Zenon Page Templates - JS (ZPT-JS)

A javascript implementation of Zope Page Templates (ZPT).

Getting started

What is ZPT-JS

Zenon Page Templates - JS (ZPT-JS) is a Javascript API that makes it easy to modify the DOM of a HTML document with no Javascript programming, using only some custom attributes. ZPT-JS is a javascript implementation of Zope Page Templates (ZPT). It is not a fully compliant implementation: there are some differences. Take a look at Zope2 book to learn about Zope Page Templates.

Core features of ZPT-JS are:

ZPT-JS and ZPT: similar but not equal

ZPT-JS is based on ZPT but it does not implement it at 100%.

Using ZPT we have:

Using ZPT-JS:

A main goal of ZPT-JS is not to break a valid HTML document. So, as HTML5 allows, instead of using TAL attributes ZPT-JS uses data attributes. This way tal:content attribute is replaced by data-content. However, ZPT-JS also supports standard TAL attributes (setting a configuration option).

Usage

A sample of template:

<!DOCTYPE html>
<html> 
    <head>
        <meta charset="utf-8">
        <title>Getting started</title>

        <script src="zpt.min.js" defer></script>
        <script src="gettingStarted.js" type="text/javascript" defer></script>
    </head>
    <body>
        <p data-content="message">
            the message
        </p>
    </body>
</html>
                

Where zpt.min.js is the minimized version of ZPT-JS and gettingStarted.js is:

"use strict";

var dictionary = new zpt.ReactiveDictionary({
    message: "Hello, world!"
});

zpt.run({
    root: document.body,
    dictionary: dictionary
});
                

The resulting body element is:

<body>
    <p data-content="message">
        Hello, world!
    </p>
</body>
                

If we change some data in the dictionary this way:

dictionary.message = "Bye, world!";
                

We don't need to do anything else, the body element now is:

<body>
    <p data-content="message">
        Bye, world!
    </p>
</body>