metal Macros from PageTemplateFiles?
Is it possible (and how?) to use a procedure in a product to produce a PageTemplate that defines a macro, that can be used in another PageTemplate? I tried: class SomeClass(Folder): content_template = PageTemplateFile("/some/file/template.zpt") and the direct ssignment to a variable works, but it is not exactly what I need (I need to check with the actual instance). But when I try to do: def content_template(self): pt = PageTemplateFile("/some/file/template.zpt") return pt then the procedure is never called and I get an error in the ZPT that tries to use the macro: Error Type: AttributeError Error Value: content_templatemacros Somewhere I read a vage reference to invoke "cook" but I don't know how. Thanks Robert
On Wed, 2005-01-19 at 14:29 +0100, Robert Casties wrote:
Is it possible (and how?) to use a procedure in a product to produce a PageTemplate that defines a macro, that can be used in another PageTemplate?
I tried:
class SomeClass(Folder):
content_template = PageTemplateFile("/some/file/template.zpt")
and the direct ssignment to a variable works, but it is not exactly what I need (I need to check with the actual instance).
But when I try to do:
def content_template(self): pt = PageTemplateFile("/some/file/template.zpt") return pt
then the procedure is never called and I get an error in the ZPT that tries to use the macro:
Error Type: AttributeError Error Value: content_templatemacros
Somewhere I read a vage reference to invoke "cook" but I don't know how.
Read the answer I already gave to your identical mail (yesterday?) :-) Regards Tino
Tino Wildenhain wrote: [...]
But when I try to do:
def content_template(self): pt = PageTemplateFile("/some/file/template.zpt") return pt
then the procedure is never called and I get an error in the ZPT that tries to use the macro:
Error Type: AttributeError Error Value: content_templatemacros
Somewhere I read a vage reference to invoke "cook" but I don't know how.
Read the answer I already gave to your identical mail (yesterday?) :-)
I already tried return pt.__of__(self) but the error is the same. Also the function doesn't seem to get called at all when the page that should use the macro is requested. (I use the __of__(self) of course for simple PageTemplates.) Regards Robert
Robert Casties wrote at 2005-1-19 14:29 +0100:
Is it possible (and how?) to use a procedure in a product to produce a PageTemplate that defines a macro, that can be used in another PageTemplate?
I tried:
class SomeClass(Folder):
content_template = PageTemplateFile("/some/file/template.zpt")
and the direct ssignment to a variable works, but it is not exactly what I need (I need to check with the actual instance).
But when I try to do:
def content_template(self): pt = PageTemplateFile("/some/file/template.zpt") return pt
then the procedure is never called and I get an error in the ZPT that tries to use the macro:
Error Type: AttributeError Error Value: content_templatemacros
Two errors: 1. as Tino already pointed out: you forgot the ".__of__(self)" 2. you must call your "content_template" method (contrary to your "content_template" attribute). The easiest way would be a "ComputedAttribute", something like from ComputedAttribute import ComputedAttribute ... def content_template(self): ... content_template = ComputedAttribute(content_template, 1)
Somewhere I read a vage reference to invoke "cook" but I don't know how.
PageTemplates get automatically "cook"ed, when necessary. -- Dieter
Dieter Maurer wrote:
def content_template(self): pt = PageTemplateFile("/some/file/template.zpt") return pt
then the procedure is never called and I get an error in the ZPT that tries to use the macro:
Error Type: AttributeError Error Value: content_templatemacros
Two errors:
1. as Tino already pointed out: you forgot the ".__of__(self)"
That was not the main problem (as I had tried that before) but I tried to use the method in a traversal "metal:use-macro="here/content_template/macros/page" which didn't work. (Could that be made to work?)
2. you must call your "content_template" method (contrary to your "content_template" attribute).
The easiest way would be a "ComputedAttribute", something like
from ComputedAttribute import ComputedAttribute
... def content_template(self): ...
content_template = ComputedAttribute(content_template, 1)
Interesting, but I don't really understand the details. Can I have an attribute and a method of the same name? What does ComputedAttribute do? I found some documentation hints on the web but what's the second parameter? Can I pass parameters to the function? Regards Robert
participants (3)
-
Dieter Maurer -
Robert Casties -
Tino Wildenhain