[Zope] processing dtml in external method

Scott Shepherd skot@pobox.com
Tue, 22 Aug 2000 18:39:38 -0400


Friends,

I have an external method that returns a string containing dtml, but 
I want it to evaluate the dtml and return the result. How do I do 
that?

I noticed in, say, 
/usr/share/zope/lib/python/Products/ExternalMethod/ExternalMethod.py, 
that dtml-containing *files* are used as object methods like this:

	from Globals import HTMLFile
	manage_main = HTMLFile( 'methodEdit', globals() )

so I figured I could do a similar thing with a dtml-containing string 
and an external method:

	from Globals import HTML
	dtml_string = '<dtml-let x="it works"><dtml-var x></dtml-let>'
	external_method = HTML( dtml_string, globals() )

This in fact works, but if I try to reference anything in the current 
object, like

	dtml_string = '<dtml-var id>'

I get KeyError: id.

Apparently I'm getting dtml evaluation but not in the context of the 
current object. What am I doing wrong, and (for extra credit) why 
doesn't ExternalMethod.py have this problem using HTMLFile?

TIA,
Scott

PS: I know I can get the id with

	def external_method( self, REQUEST = None ):
		return self.id

but the real dtml_string I need to evaluate is much more complicated 
than '<dtml-var id>'...