trying to understand ZPT macros...
starting to play with ZPT, and I've hit something that I Just Don't Get: metal. I've got something like this: <div class="lgOther" tal:define="linkgroup python:blog.linkGroups.get('blogs')"> <div class="lgOtherTitle" tal:content="linkgroup/title"> title here </div> <div class="lgOtherEntry" tal:repeat="bloglink linkgroup/getLinks"> <a tal:attributes="href bloglink/URL" tal:content="bloglink/text" href="">sample link</a> </div> </div> and I want to make it a macro, so that I can do something like <div class="lgOther" metal:use-macro="macros/renderLinkGroup" tal:define="linkgroup python:blog.linkGroups.get('blogs')"/> <div class="lgOther" metal:use-macro="macros/renderLinkGroup" tal:define="linkgroup python:blog.linkGroups.get('media')"/> but if I try something like <span metal:define-macro="renderLinkGroup"> <div class="lgOtherTitle" tal:content="linkgroup/title"> title </div> <div class="lgOtherEntry" tal:repeat="bloglink linkgroup/getLinks"> <a tal:attributes="href bloglink/URL" tal:content="bloglink/text" href="">sample link</a> </div> </span> <div class="lgOther" tal:define="linkgroup python:blog.linkGroups.get('blogs')" metal:use-macro="macros/renderLinkGroup"> </div> I get a keyerror on 'linkgroup' in the macro definition... I'm trying to (essentially) pass a single argument to the renderLinkGroup macro. I assume I need to do this with slots, but it's not clear to me at all how you use a slot for something that's not a bit of HTML. There's something I'm just not grokking here - I've read all the online docs I could find, and have had no luck at all. Thanks for any help.
Anthony Baxter wrote:
<div class="lgOther" metal:use-macro="macros/renderLinkGroup" tal:define="linkgroup python:blog.linkGroups.get('blogs')"/>
I get a keyerror on 'linkgroup' in the macro definition...
That's because the metal:use-macro replaces the entire <div> with the macro before the tal:define has a chance to do anything (it also blows away your "class" attribute). This should work if you change it to: <div tal:define="linkgroup python:blog.linkGroups.get('blogs')"> <div metal:use-macro="macros/renderLinkGroup"></div> </div> Cheers, Evan @ 4-am
participants (2)
-
Anthony Baxter -
Evan Simpson