METAL stands for 'Macro Extension for TAL'. This namespace, supported by PHPTAL, allows template designers to define and call xml/xhtml macros.
This attribute declares a macro. Think of macros as library of small templates which can be reused in any other template.
<div metal:define-macro="main_menu">
<ul>
<li><a href="/">home</a></li>
<li><a href="/products">products</a></li>
<li><a href="/contact">contact</a></li>
</ul>
<div>
Last modified:
<span tal:content="mdate">page modification date</span>
</div>
</div>
Macros inherit from the caller's dictionary. In the above example, the variable 'mdate' depends on the template that calls the macro.
This attribute calls a macro and includes its result in the current template.
<span tal:comment="main_menu template requires 'mdate' variable" tal:define="mdate page/last_modified" metal:use-macro="main_menu" />
You can refer to external macros defined in other templates by specifying the template source file.
<span metal:use-macro="site_macros.html/main_menu"/>
It is interesting to note that you can also use the PHPTAL inline replacement feature inside the use-macro attribute value:
<span metal:use-macro="${design}/site_macros.html/main_menu"/>
This attribute must appear under a metal:define-macro tag.
Slots can be replaced by caller template with some custom dynamically-generated XML/XHTML.
Slots can be thought of like reverse includes, a macro can be an entire page and slots customize this page depending on the URL. For instance, a slot may contain the latest news in the home page or user actions when the member is logged in.
<span metal:define-slot="news_place">
<table>
<tr tal:repeat="item php:latestNews()">
<td tal:content="item/value">news description</td>
</tr>
</table>
</span>
The above example defines a place called 'news_place' which can be overwritten by caller templates. See next section for the continuation of this example.
This attribute occurs only under metal:use-macro context.
This explicitly tells PHPTAL to replace a defined slot with the content provided under the metal:fill-slot attribute.
<span tal:condition="logged" metal:fill-slot="news_place">
<h2>user menu</h2>
<ul>
<li><a href="/user/action/inbox">inbox</a></li>
<li><a href="/user/action/new">new mail</a></li>
<li><a href="/user/action/disconnect">disconnect</a></li>
</ul>
</span>
Slots give the opportunity to define really customizable and reusable page templates with a simple push technology.