[Zope] TAL: Replacing an attribute in a macro call
David Chandek-Stark
dc at duke.edu
Thu Jun 3 09:17:16 EDT 2004
You can define a variable before calling the macro:
<div tal:define="select_name string:foo">
<div metal:use-macro="macro_path">
[select_name value is 'foo']
</div>
</div>
<div tal:define="select_name string:bar">
<div metal:use-macro="macro_path">
[select_name value is 'bar']
</div>
</div>
Macro:
<div metal:define-macro="user>
<select tal:attributes="name select_name">
</select>
</div>
Of course, you'll probably want to do some condition/error checking ...
--David
Mark Roach wrote:
> I have a macro defined for a "select" item that I now would like to put
> twice in my page. This means I need to have to different names for the
> items, but I can't seem to figure out how to change an attribute while
> calling a macro. My macro definition looks like this:
>
> <select metal:define-macro="user" name="user" tal:define="items python:container.function()">
> <div tal:repeat="option items" tal:omit-tag="">
> <option tal:content="option/data">Call Type</option>
> </div>
> </select>
>
> What I had hoped I could do is use the macro like this:
>
> <select metal:use-macro="container/selects/macros/user" name="somethingelse">
> ...
> </select>
>
> but this doesn't work as the macro overwrites that attribute with its
> own (which makes sense). I have tried leaving the name undefined in the
> macro, but it then renders without a name.
>
> What is the "correct", or at least idiomatic way to do this?
>
> Thanks,
>
> Mark Roach
>
>
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
--
David Chandek-Stark
Web Applications Developer
Duke University - Perkins Library
(919) 660-5859
dc at duke.edu
More information about the Zope
mailing list