[ZPT] Passing "options" keyword arguments to a PageTemplateFile?
Jon Whitener
wmmail@twmi.rr.com
Fri, 14 Feb 2003 17:20:15 -0500
Evan Simpson wrote:
> Jon Whitener wrote:
>> I'm creating a file-system-based product for Zope. In my main
>> product class module, I have defined a list of "categories". I'm
>> trying to pass the list as a keyword argument to a Page Template so
>> I may access the attribute within the ZPT via the "options"
>> built-in keyword.
>
> If the Page Template is a "method" of your class, then you would
> probably be better off defining a "get_categories()" method on the
> class and using "container/get_categories" instead of "options".
>
Thanks for your response, Evan. I want to make sure I understand you
correctly, because what I attempted with your advice gave me an
Attribute Error on "get_categories" when I called the template from
the ZMI.
I've pared this product down to the smallest possible bits to try and
work this out. The Minimal product only has one "constructor" in the
__init.py__ file, the "index_html" method (so I can see the results of
the ZPT when I select "Minimal" from the Product Add list in the ZMI).
Whether I use "container", "here", "template", I get the same
Attribute error because Zope apparently isn't looking in the
MinimalModule. Any further ideas would be like gold to me.
Thanks again,
Jon Whitener
Detroit Michigan USA
__init.py__
------------
import MinimalModule
def initialize(context):
"Initialize the Minimal product."
context.registerClass(
MinimalModule.Minimal,
constructors = (MinimalModule.Minimal.index_html,)
)
MinimalModule.py:
-----------------
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
class Minimal:
"Minimal object"
meta_type = "Minimal"
def get_categories(self):
" Return a list of categories "
return ['Arts', 'Culture', 'Family']
index_html = PageTemplateFile('www/index_html', globals())
www/index_html.zpt:
----------------------
<html>
<body>
<p tal:content="container/get_categories">CATEGORIES!</p>
</body>
</html>