[Zope] Flexible path generation for metal:use-macro with Python (KeyError)
Dieter Maurer
dieter@handshake.de
Wed, 4 Dec 2002 22:40:27 +0100
Thomas Duebendorfer writes:
> I am looking for a flexible way to define the path for a macro to be used.
>
> The following works:
> <span metal:use-macro="here/content_macro_main.html/macros/main |
> here/content_macros.html/macros/main |
> here/content_macros.html/macros/no_main_content">
> ....
> Now, I would like to generate this sequence of alternative paths by a
> Python script to have full flexibility. Therefore I tried the following
> approach:
>
> Create a Python "getMacroPath" script that takes the parameter "macroname"
> and looks like this:
> return 'here/content_macro_main.html/macros/' + macroname
Thus, your script returns a string (representing a path expression)
and you want to get the designated object.
The "path" function does this: it take a string and evaluates it
as a path.
Use: "python: path(here.getMacroPath(...))"
Dieter