[Zope] Adding a ZPT when adding product instance

Lee Harr missive at hotmail.com
Sat Jan 10 10:33:42 EST 2004


> >I use something like this to add a DTML Method inside of my folderish
> >product:
> >
> >    # Add default interface
> >    index_html = HTMLFile('dtml/index_html', globals())
> >    text = index_html.read_raw()
> >    ob.manage_addDTMLMethod(id='index_html', title='')
> >    idx = ob.index_html
> >    idx.manage_edit(text, title='')
> >
> >
> >the source for the index_html file is in the dtml folder in my product,
> >and is called index_html.dtml
> >
> >Is this the correct Zope idiom?
> >How can I do something similar for ZPT?
>
>It is similar for ZPT.
>
>ZPT use the "official" creation method (not an abbreviated form
>like DTML). It looks like:
>
>      ob.manage_addProduct['PageTemplates'].manage_addPageTemplate(
>        id, title, text)
>
>"PageTemplateFile" is the correspondence for "HTMLFile".
>However, I would directly read the file content (with Python's
>"open" followed by "read") and pass it as "text" to the
>constructor.
>



Ok. That was actually my first thought, but how do I find the directory
in which my product?  This is how I have done it ...


    dirname = os.path.dirname(__file__)
    zpt = os.path.join(dirname, 'zpt')
    index_html = open(os.path.join(zpt, 'index_html.zpt'))
    text = index_html.read()
    ob.manage_addProduct['PageTemplates'].manage_addPageTemplate(
        'index_html', '', text)


I could not find PageTemplateFile from my script... it is not in Globals 
with
HTMLFile.

I also found package_home in Globals while looking through
ZopePageTemplate.py but I am not quite sure how to use it.

Thank you for your time.

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus




More information about the Zope mailing list