[Zope] Accessing a macro slot from Python
Bryn Thomas
brynthomas at red24.info
Tue Oct 19 15:39:51 EDT 2004
Thanks for this answer! I never realised that the scope of the local
metal:params extended all the way within the tag block.
I see by your example that you use <metal:params tal:define="variablename
python:22"> to set variablename to be an integer of 22. I've used the Zope
"variablename string:mystring" syntax to set a variable to be a string, and
I then tried several combinations of things like "variablename int:myint"
and "variablename integer:myint" etc etc, with no success. Assumedly then
you use the syntax "variablename python:mynonstringvariable" to set
variables of pretty much any non-string type.
Regards,
Bryn
-----Original Message-----
From: Dieter Maurer [mailto:dieter at handshake.de]
Sent: 19 October 2004 08:15 PM
To: Bryn Thomas
Cc: zope at zope.org
Subject: Re: [Zope] Accessing a macro slot from Python
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