[ZPT] complex macro usage
James Carroll
jim at microbrightfield.com
Sat Apr 24 13:20:55 EDT 2004
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zpt/attachments/20040424/fd243df1/attachment.html
More information about the ZPT
mailing list