[Zope] Using DTMLFile or PageTemplateFile in methods
Peter Bengtsson
mail@peterbe.com
Mon, 23 Jul 2001 12:26:03 +0200
Still not working!
It was::
index_html = PageTemplateFile('index', globals())
which was working fine
I tried::
def index_html(self):
" "
return "<html>hello</html>"
which also worked.
Then I tried::
def index_html(self):
" "
# 'simple' only contains "<html>hello</html>"
return PageTemplateFile('simple', globals())
which caused a NotFound supposedly meaning that the index_html was "broken".
I also tried your advice::
def index_html(self):
" "
# 'simple' only contains "<html>hello</html>"
# call, call the PageTemplateFile() so that it returns HTML, not
object
return PageTemplateFile('simple', globals()) ()
which gives me this error:
Error Type: AttributeError
Error Value: 'string' object has no attribute 'other'
File C:\Program Files\zope\lib\python\Shared\DC\Scripts\Bindings.py, line
351, in _bindAndExec
(Object: simple)
File <string>, line 1, in ?
File C:\Program Files\zope\lib\python\Shared\DC\Scripts\Bindings.py, line
304, in _getTraverseSubpath
(Object: simple)
AttributeError: (see above)
Bare in mind that 'simple.zpt' contains only <html>hello</html> and works
fine the static way.
If this is a bug or can't be done easily, I'm going to have to use my .zpt
files to create ZPT instances in Zope instead.
> Peter Bengtsson writes:
> > 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?
> The second approach need an additional "call".
>
> ZPublisher is ready to call the "index_html" once.
>
> In the first case, this calles in fact the PageTemplate
> and back comes the rendered template.
>
> In the second case, ZPublisher again calls "index_html"
> but the result is the PageTemplate itself, and not
> the rendered result.
>
> Use:
>
> def which_index_html(self):
> return PageTemplateFile('index', globals())()
>
> i.e. "call" the PageTemplate!
>
>
>
> Dieter