Defining and using METAL macros
metal:define-macro
Attribute syntax
metal:define-macro="MACRONAME"
Remarks
Indicates that the current element and all of its child elements form a macro with the given name
(MACRONAME). Alone this attribute does nothing, but the macro may now be referenced by either
use-macro
or metal:extend-macro
attributes.
metal:use-macro
Attribute syntax
metal:use-macro="EXPRESSION"
Remarks
Creates a copy of the markup tree represented by the macro EXPRESSION ("the macro"). The macro is
extended and slots are filled
if appropriate. Then the current element (the element decorated use-macro
) and its
children/content is replaced with the referenced macro (the corresponding element decorated with
define-macro
).
Macro definition and usage example
The following simple example shows a common page header macro:
<!-- Macro definition -->
<body>
<header metal:define-macro="page_header">
<a href="homepage_url">Boyd's toast</a>
<p class="strapline">Our toast really <em>pops!</em></p>
</header>
</body>
<!-- Macro usage -->
<body>
<header metal:use-macro="page_header">Uses the common header</header>
<section class="main_content">
<p>Here's the main page content</p>
</section>
</body>
<!-- How this renders -->
<body>
<header>
<a href="homepage_url">Boyd's toast</a>
<p class="strapline">Our toast really <em>pops!</em></p>
</header>
<section class="main_content">
<p>Here's the main page content</p>
</section>
</body>