[Zope] ZPT instead of DTML in products - how?

Evan Simpson evan@4-am.com
Mon, 24 Jun 2002 10:37:35 -0500


John Schinnerer wrote:
> I'm crawling up the zope/python products learning curve...if I want to
> use ZPT instead of DTML for web interfaces (like index_html,
> manage_addForm, etc.), how do I specify that?  For DTML I find
> tutorials and howtos showing this sort of thing:
> 
>   from Globals import DTMLFile
> 
>     index_html = DTMLFile('www/index_html', globals())
>     manage_addForm = DTMLFile('manage_addForm', globals())
> 
> ..what is the equivalent of the above for ZPT files instead of DTML
> files?

from Products.PageTemplates.PageTemplateFile import PageTemplateFile

   index_html = PageTemplateFile('www/index_html', globals())
   manage_addForm = PageTemplateFile('manage_addForm', globals())

Not so bad, eh? ;-)  Some minor notes:  If you omit the file's extension 
  as above, the file must have extension '.zpt'.  If the base name of 
the file is different than the method name, you should add the keyword 
argument '__name__', as in:

   manage_addForm = PageTemplateFile('addForm', globals(),
     __name__='manage_addForm')

Also, unlike DTMLFiles, PageTemplateFiles operate within the same 
restrictions as through-the-web PageTemplates (such as no access to 
names starting with underscores).

Cheers,

Evan @ 4-am