[ZPT] trying to understand ZPT macros...

Anthony Baxter anthony@interlink.com.au
Thu, 09 Jan 2003 00:34:55 +1100


[resent - initially sent this to the main zope list - richard commented
to me that it wasn't likely to get a response there]

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     <anthony@interlink.com.au>
It's never too late to have a happy childhood.