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:
- Internal macros. They are defined in the same file where they are invoked.
- External macros. They are defined in another file.
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
- In ZPT the syntax is argument ::= Name, so all invokations are literals. ZPT-JS uses expressions.
- Syntax of external macro invokation.
- There is no Zope tree in which to locate templates.
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.