[ZPT] Macro parameters too weak (was: [Zope] METAL & parameters?)

Dieter Maurer dieter@handshake.de
Sat, 23 Feb 2002 13:31:38 +0100


alan milligan writes:
 > I have a METAL define which just draws a pretty little box with a title and 
 > content:
 > 
 > <div metal:define-macro="box">
 >   ...
 >      <table border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF" 
 >   ...
 > </div>
 > 
 > What I would like to be able to do, is set the "bgcolor" attribute 
 > dynamically when using this macro.
It's a big weakness (I my view) that ZPT macros only support
slots as parameters. Slots are restricted to (HTML/XML) sub-elements,
but often, we need way to have attribute values are parameters (as
in your case).

I work around this weakness by using unbound variables inside the macro
definition:

     <... metal:define-macro=...>
       <table border="0" ... bgcolor="#FFFFFF"
          tal:attributes="bgcolor box_bgcolor"
       >
     </...>

When the macro is used, the caller uses something like:

     <tal:div tal:define="box_bgcolor string:#000000">
	....
        <... metal:use-macro=...>
	</...>
	....
     </tal:div>

This works but the disadvantages are obvious:

  *  Unbound variables are very difficult to spot.

     Combined with a lacking documentation facility for macros,
     this make reuse and maintenance quite difficult.

  *  At least the template gets artificial elements (e.g. the "tal:div" above).
     It clutters the ZPT (not a big problem, just a nuisance).


I would very much like to see explicit parameter passing for
definitions...


Dieter