[Zope] Dynamically render DTML?

Kapil Thangavelu kthangavelu@earthlink.net
Sun, 17 Sep 2000 12:07:19 -0700


Kapil Thangavelu wrote:
> 
> "Mark N. Gibson" wrote:
> >
> > Is it possible to return dtml from python, and have it rendered correctly
> > on the page?
> >
> > for example, the python might look like this...
> >
> > def get_header(somevar=1):
> >   if somevar==1:
> >    return '<dtml-var standard_html_header>'
> >   else:
> >    return '<dtml-var other_html_header>'
> >
> > The dtml document in the zodb might look like this...
> >
> > <dtml-var expr="get_header(1)">
> >    Body text....
> > <dtml-var standard_html_footer>
> >
> > When this gets rendered, it's as if the dtml document had
> > <dtml-var standard_html_header> in place of the get_header call.
> >
> if you want to achieve this result from python you can evaluate/call the
> standard_html_header in python and return the resultant string. see the
> arguements for DTMLMethod in the /lib/python/OFS folder for exact
> syntax.


to clarify on the python solutions, the options that i see are either

1. calling the dtml method. if you have a reference to the method than
you call it directly. something like

return standard_html_header()

refer to lib/python/OFS/DTMLMethod.py for calling syntax & args

2. evalutate an arbitrary dtml string ala '<dtml-var
standard_html_header>', something like

return HTML('<dtml-var standard_html_header>')()

refer to lib/python/OFS/DocumentTemplate/ for exact syntax && args.