[ZPT] trying to understand ZPT macros...
Clemens Robbenhaar
zpt@zope.org
Wed, 8 Jan 2003 14:46:28 +0100
Hi Anthony,
[...]
> 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...
>
This happens because the 'metal:use-macro' eats the complete tag,
including the 'tal:define', which is not executed at all.
You need to do double nesting like:
<tal:params define="linkgroup python:blog.linkGroups.get('blogs')">
<metal:block use-macro="macros/renderLinkGroup" />
</tal:params>
(I personally prefer to use '<tal:' and '<metal:' tags instead of
'tal:', 'metal;' attributes, if the tag will not be rendered anyway due
to TALES/METAL substitution.)
Warning: untested code. I guess it should work because similar code
works for me in similar situations.
Hope this helps.
Clemens