Hello all. Zope Book have example (http://www.zope.org/Documentation/Books/ZopeBook/current/AdvZPT.stx): <p metal:use-macro="python:here.getMacro()"> Replaced with a dynamically determined macro, which is located by the getMacro script. </p> Can you explain this example and show simple script? """ return 'path/to/zpt/macros/some' """ don't work. -- Mikhail 'Xen' Kashkin
Mikhail wrote:
<p metal:use-macro="python:here.getMacro()">
Can you explain this example and show simple script? """ return 'path/to/zpt/macros/some' """ don't work.
"getMacro" cannot return a string -- it must return the actual macro object. One way to accomplish this is to use the "restrictedTraverse" method on your path string, like so: return context.restrictedTraverse('path/to/library.zpt/macros/some') Slightly more efficient, if your path is static, would be the following: return context.path.to['library.zpt'].macros.some On the other hand, you *could* return a path string, if you change your use-macro to: <p metal:use-macro="python:path(here.getMacro())"> Cheers, Evan @ 4-am
Evan Simpson wrote:
Mikhail wrote:
<p metal:use-macro="python:here.getMacro()">
Can you explain this example and show simple script? """ return 'path/to/zpt/macros/some' """ don't work.
"getMacro" cannot return a string -- it must return the actual macro object. One way to accomplish this is to use the "restrictedTraverse" method on your path string, like so:
return context.restrictedTraverse('path/to/library.zpt/macros/some')
Slightly more efficient, if your path is static, would be the following:
return context.path.to['library.zpt'].macros.some
On the other hand, you *could* return a path string, if you change your use-macro to:
<p metal:use-macro="python:path(here.getMacro())">
Cheers,
Evan @ 4-am
thanks your explanation solve my poblems. -- Mikhail 'Xen' Kashkin (Russia)
participants (2)
-
Evan Simpson -
Mikhail