ZPT-JS reference - Attributes - METALDefineMacro

Syntax

argument ::= expression
                

Description

The data-define-macro statement defines a macro. The macro is named by the statement expression, and is defined as the element and its sub-tree. Macros makes it easy to write it once and use it several times.

In ZPT-JS, there are 2 types of macros:

An example of internal macro: to access a macro named copyright in the same file you could use the path expression:

'copyright'
                

An example of external macro: to access a macro named copyright in a file named macros.html, you could use the path expression:

'copyright@macros.html'
                

Note: some parts extracted from Zope Page Templates Reference.

Differences with ZPT

Examples

Simple macro definition:

<p data-define-macro="copyright">
    Copyright 2019, <em>Foo, Bar, and Associates</em> Inc.
</p>
                

An important issue about using id attribute: don't set id attribute without using data-tattributtes, ZPT-JS copies the node inside the macro definition so you are at risk of having got several HTML elements with the same id. So don't do:

<p data-define-macro="copyright">
    Copyright 2019
</p>
                

We can fix it using data-tattributtes and defining different values for year-suffix variable:

<p data-define-macro="copyright">
    Copyright 2019
</p>
                

Note: some parts extracted from Zope Page Templates Reference.