[ZPT] Can macros be employed in Page Templates outside of Zope?

Evan Simpson evan@zope.com
Thu, 30 Aug 2001 10:13:31 -0400


Hamish Lawson wrote:

> I thought I would try again and see whether it was now possible to
> refer to the outer page from within the inner page via 'container', but
> without avail. Presumably this is because container is normally a Zope
> folder (rather than a filesystem folder) and so is only defined in a
> Zope environment (I'm guessing by ZopePageTemplate). When calling a
> template outside Zope, is there some kind of object with the necessary
> behaviour that could be passed as a 'container' option?

You would need to write one, although it could be as simple as:

class FSPageTemplateFolder:
     def __init__(self, basepath):
         self._basepath = basepath
     def __getitem__(self, name):
         fn = os.path.join(self._basepath, name)
         if os.path.isdir(fn):
             return FSPageTemplateFolder(fn)
         txt = open(fn).read()
         pt = PageTemplate()
         pt.write(txt)
         return pt

This is horribly inefficient, but it's a start.

Cheers,

Evan @ Zope