[Zope] Flexible path generation for metal:use-macro with Python (KeyError)
Thomas Duebendorfer
duebendorfer@tik.ee.ethz.ch
Wed, 4 Dec 2002 00:49:43 +0100 (CET)
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">
It tries to locate the macro "main" first in the file
content_macro_main.html and if that fails, ZOPE tries to find it in
content_macros.html and if that fails too, the macro "no_main_content" in
content_macros.html is called.
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
(Of course, the script will finally generate many paths separated by "|")
In the ZOPE Page Template mydoc.html I use:
<span tal:omit-tag="" tal:define="macropath python:here.getMacroPath('main')">
<span metal:use-macro="here/?macropath">
<!-- main slot -->
<H2>Welcome</H2>
<P>We welcome you to our website.</P>
</span>
</span>
The Python script seems to work correctly, but ZOPE complains with
the error:
Error Type: KeyError
Error Value: here/content_macro_main.html/macros/main
However, I don't see why METAL and/or ZOPE cannot deal with a TAL variable
that has the correct value when it can deal with the same value as a
string itself. Any ideas?
Regards,
Thomas Duebendorfer