[Zope] Dynamically render DTML?
Kapil Thangavelu
kthangavelu@earthlink.net
Sun, 17 Sep 2000 09:15:07 -0700
"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.
>
to have your example work would require multiple or nested passes of the
dtml-evalutation machinery. so no you can't return a string containing
dtml and expect it to be evalutated. the machinery expects you to return
a
string or value (for dtml-var) to which it will apply formatting rules.
on the web the evalutation machinery automatically calls (possibly
nested) dtml tags, so this is not a concern, but again it only performs
the evaluation once.
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.
doing it from a dtml method would be easier assuming it fits the usage.
<dtml-call "REQUEST.set('somevar', getvaluefromsomewhere()">
<dtml-if "somevar==1">
<dtml-var standard_html_header>
<dtml-else>
<dtml-var other_html_header>
</dtml-if>
Cheers
Kapil
> I understand how to call external methods from dtml, etc. I just want
> to know if it's possible to get the string returned rendered as dtml.
>
> Mark
>
> ---------------
> Mark Gibson
> Kaivo, Inc.
> www.kaivo.com
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )