[Zope] Re: Page Template Dynaics

Evan Simpson evan@4-am.com
Mon, 09 Dec 2002 10:57:56 -0600


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