[Zope] Accessing a macro slot from Python

Dieter Maurer dieter at handshake.de
Tue Oct 19 14:14:39 EDT 2004


Bryn Thomas wrote at 2004-10-19 01:17 +0200:
> ...
>I'm trying to get a Zope Page Template to use a macro which is passed a few
>parameters that need to be accessed by Python. I was under the impression
>that "define-slot" and "fill-slot" where the appropriate ways of passing
>parameters, but I'm really struggling to use these slots from within Python
>expressions in the macro.

"slot"s are paramters but of a different type (they provide content
not variables).

>My macro looks like so:
>
><span metal:define-macro="pullActivityReport">
>	<tr tal:repeat="update
>python:container.get_updates_made(templateid=MYTEMPLATEIDSLOT)">
>		<td><span tal:replace="update/topicname">Topic
>Name</span></td>
>	</tr>
></span>	
>
>While my main page looks like:
>
><table>
>    <span metal:use-macro="container/macroDefs/macros/pullActivityReport">
>	<span metal:fill-slot="MYTEMPLATEIDSLOT">22</span>
>    </span>
></table>

Use instead:

    <table>
      <metal:params tal:define="MYTEMPLATEIDSLOT python:22">
        <span metal:use-macro="..." />
      </metal:params>
    </table>


Note that "metal:XXX" tags are silently omitted.
Aside from this, there is nothing special with "metal:params",
you can use any other tag you like for documentation purposes.

-- 
Dieter


More information about the Zope mailing list