METAL also introduces the concept of "slots" within a macro, which may in turn be populated by other macros. Slots are placeholders within a macro definition, which can be populated dynamically every time you use the macro.
Let's take a simple example to demonstrate how this works. Here's the macro definition, which contains a placeholder, or slot, named "link":
Today's special is <span metal:define-slot="title"></span>
And here's the template which uses it - note how the placeholder has been filled
with an actual value using the "fill-slot" attribute:
is <span metal:fill-slot="title"><a
Here's what the output looks like:
By using a slot within a macro, I have the option of reusing the macro multiple times, and replacing the slot with different data each time I use it. This adds a tremendous amount of reusability to the macro, and can thereby substantially simplify the task of developing almost-but-not-quite-identical programming routines.
Here's another, more realistic example - a macro which sets up the basic skeleton for a Web page, and uses slots to populate each instance of that page with different content:
Here's a sample Web page that uses the macro, and defines a particular look for
the main body:
Select from the list below:
goes here <p>Content goes here <p>Content goes here <p>Content
<p> </center> </span> </span>
Here's the output:
And here's another one that uses the same macro, but a different look for the body: