[ZPT] complex macro usage

Fernando Martins fernando at cmartins.demon.nl
Tue Apr 27 17:44:58 EDT 2004


Hi,

please avoid HTML messages in this list. You have no idea how bad it looks
in my side ;-)

Honestly, I don't quite get what you want not even what do you perceive as
complex, but as you got no other reply so far, I'll do some guess work.

It seems your problem is to pass some arguments (variables) to a macro. This
doesn't work because macros are coarse grained: you can only pass through
entire HTML elements. You should also keep in mind that macros are not
running code, it's just a way to do string replacemente; the concept of
subroutines or variables doesn't really apply here.

The trick to overcome this is to put your variables in the HTML elements
above (tree speaking) the element having the use-macro. These variables must
have the same name as the ones in the macro so that when your macro is used
("imported") all the names match up.

HTH,
Fernando

James Carroll wrote:
=======================
Hi, I'd like to do something that is probably too complex for a
metal:define-macro.  I've got a complex set of javascript and html for a
javascript date selector, and it would be great to get the complexity out of
my page templates.

I'd like to do something like the (invalid) following code:

<span  metal:define-macro="dateInput"
       tal:define="name <metal:fill-slot="name">"
       tal:define="idname string:${name}id"
       tal:define="buttonname string:${name}button"
       tal:define="initalValue <metal:fill-slot="value">">

In here I would use name, idname, buttonname and initalvalue repeatedly,
including inside some dynamically generated javascript.  (I've pasted the
complex stuff below.)

</span>

Even though I would like to use macros for this sort of thing, I think it's
too complex to ever work.  I'm thinkning of doing it with a python script,
then I would

<span tal:replace="dateInput python:here.makeDateSelector('shipDate',
shipment['date'])"></span>

but this doesn't seem right either.  I'm coming from a background of some
complex JavaWebComponents in the Tapestry framework.

What's the best way to do this sort of thing?



The real body of my macro is something like:

<span  metal:define-macro="dateInput"
       tal:define="name string:jim">

<input type="text" name="receivedFromCustomer" id="recFromCust"
value="8/27/2003" size="12" tal:attributes="value rma/receivedFromCustomer |
nothing" onBlur="magicDate(this)"/>
<button type="reset" id="recFromCustButton">...</button>
<script type="text/javascript">
    Calendar.setup({
        inputField     :    "recFromCust",      // id of the input field
        ifFormat       :    "%m/%d/%Y",       // format of the input field
        showsTime      :    true,            // will display a time selector
        showsWeek      :    false,            // made this up (jc)
        button         :    "recFromCustButton",   // trigger for the
calendar (button ID)
        singleClick    :    true,           // double-click mode
        step           :    1                // show all years in drop-down
boxes (instead of every other year as default)
    });
</script>
</span>

So you see I have a lot of javascript where I probably can't use
metal:fill-slot.

Thanks in advance!
-Jim




More information about the ZPT mailing list