Re: [Zope] Dynamically render DTML?
Mark N. Gibson writes: > The heart of it is that I'd like to have the Zope evaluate an arbitrary string > as if it were a DTMLMethod You may want to look at the DocumentTemplate packages. This packages is used to implement Zope's DTML objects (these objects add persistence which you do not need). One of the source files, I think it was "DocumentTemplate.DT_String" contains a good source documentation which tells you how to use DocumentTemplate in your Python code. Dieter ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Dynamically render DTML?
Thanks too all who replied, I may have simplified my problem a little too much before posting it. The heart of it is that I'd like to have the Zope evaluate an arbitrary string as if it were a DTMLMethod For those interested, here is what I ended up doing... -- pyfile.py from OFS.DTMLMethod import DTMLMethod class myclass: """ a callable object: This is acting as a base class for a ZClass """ def __call__(self,REQUEST): """a callable object - I pass in REQUEST because my dtml-vary seems to require it """ # create your dtml string - note: the idea is, this doesn't have to be a static string... text= '\ ENGLIS TITLE\ THIS IS ENGLISH CONTENT\ \ THSI IS FRENCH CONTENT\ \ Spanish title\ This is spanish text\ ' met h=DTMLMethod() # populate the DTMLMethod meth.manage_edit( text,'THIS IS THE TITLE') #the DTMLMethod goes out of scope here, so it's never persistent ( I hope ). return meth(REQUEST) -- I call this from from zope as follows... - m1 is an instance of a ZClass that has myclass as a base class. this calls myclass.__call__(self,REQUEST) - This solution worked for me. It would still be nice if I didn't have to pass REQUEST explicitly. I could have derived myclass (or the ZClass) from DTMLMethod, but I didn't need the DTMLMethod itself to be persistent. Also, I'm not sure how to intercept __call__ and pas it on to the DTMLMethod. It's a little ugly, but it works. It would be nice to be able to just say in zope and have it render. Mark 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 '' > > else: > >return '' > > > > The dtml document in the zodb might look like this... > > > > > >Body text > > > > > > When this gets rendered, it's as if the dtml document had > > 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. > > > > > > > > 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 - [EMAIL PROTECTED] > > 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 ) > > ___ > Zope maillist - [EMAIL PROTECTED] > 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 ) ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Dynamically render DTML?
As a follow-up, is it possible to evaluate DTML that is returned from an SQL Query? -Magnus ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Dynamically render DTML?
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 '' > > else: > >return '' > > > > The dtml document in the zodb might look like this... > > > > > >Body text > > > > > > When this gets rendered, it's as if the dtml document had > > 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 '', something like return HTML('')() refer to lib/python/OFS/DocumentTemplate/ for exact syntax && args. ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] Dynamically render DTML?
"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 '' > else: >return '' > > The dtml document in the zodb might look like this... > > >Body text > > > When this gets rendered, it's as if the dtml document had > 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. 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 - [EMAIL PROTECTED] > 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 ) ___ Zope maillist - [EMAIL PROTECTED] 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 )
[Zope] Dynamically render DTML?
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 '' else: return '' The dtml document in the zodb might look like this... Body text When this gets rendered, it's as if the dtml document had in place of the get_header call. 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 - [EMAIL PROTECTED] 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 )