[Zope3-dev] New METAL extension feature

shane at hathawaymix.org shane at hathawaymix.org
Mon Nov 22 13:12:37 EST 2004



On Mon, 22 Nov 2004, Amos Latteier wrote:

> Shane Hathaway wrote:
>
>> On the Zope 3 trunk, I have enhanced METAL to allow use-macro and
>> define-macro in the same tag.
>
> Great. This is an idea I've been interested in for a while.
>
>> The only TAL language change
>> is that you can now use both metal:define-macro and metal:use-macro in a
>> single tag; this used to be an error.  Macro extension is much like
>> defining a class that inherits from a single base class.  The slots are
>> like methods that can be overridden.
>
> Can you clarify how slots are redefined?

Let's say some graphic designers get together and develop a nice skin. 
Here is its page macro:

<html metal:define-macro="page">
  <head>
   <metal:block define-slot="headers" />
   <title metal:define-slot="title">Cool Skin</title>
  </head>
  <body>
   <div metal:define-slot="content" />
   <div metal:define-slot="footer" />
  </body>
</html>

An independent company wants to customize that skin, replacing certain 
slots.  The company would use macro extension:

<html metal:define-macro="page"
       metal:use-macro="coolskin_page">
  <head>
   <title metal:fill-slot="title">
    <span tal:replace="context/title">Stuff</span>
    - ACME Inc.
   </title>
  </head>
  <body>
   <div metal:fill-slot="footer">Copyright 2004 ACME Inc.  See terms before 
copying any material from this site.</div>
  </body>
</html>

Now in all of the templates that use the standard page macro, the 
company's enhancements get layered over the cool skin.  Their application 
templates can replace slots inherited from both the custom skin and the 
cool skin.  An example application template:

<html metal:use-macro="page">
  <head>
   <metal:block fill-slot="headers">
    <meta http-equiv="refresh" content="30; URL=."></meta>
   </metal:block>
  </head>
  <body>
   <div metal:fill-slot="content">
    Here's what's going on at ACME right now.
   </div>
  </body>
</html>

The resulting page will have the refresh header, the custom title, the 
content, and the footer.

Shane


More information about the Zope3-dev mailing list