[Zope] Using DTMLFile or PageTemplateFile in methods

Peter Bengtsson mail@peterbe.com
Thu, 19 Jul 2001 16:05:24 +0200


I use ZPT files for my templates for my Python product development.
This is what I do:

def manage_addInstance(self,id):
     self._setObject(id, Instance(id))

class Instance(SimpleItem):
      def __init__(self,id):
             self.id = id
      # in the products folder there is a file called index.zpt
      index_html = PageTemplateFile('index', globals())

Now, this works, but consider the following extension to the class.

class Instance(SimpleItem):
      def __init__(self,id):
             self.id = id
      def which_index_html(self):
             return PageTemplateFile('index', globals())

      index_html = which_index_html

That does NOT work! It looks like a small change, but I might be wrong.
How to do this anyone?

In my product the templates used will change inside the instance, so that
/mysite/instance1 uses one template and /mysite/instance2 uses another.

Cheers, Peter