Scott Shepherd wrote:
> 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/,
> 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 have this problem using HTMLFile?
> TIA,
> Scott
> PS: I know I can get the id with
>         def external_method( self, REQUEST = None ):
>                 return
> but the real dtml_string I need to evaluate is much more complicated
> than '<dtml-var id>'...

i'm a bit sleepy so this will be short. i've used the DocumentTemplate
stuff outside of zope and its pretty well done. if you want examples of
how to do it check out the tests in the Document Template directory. to
your questions.

you can pass in explicit named variables in a second arg/call to the
template system. like

HTML("python string")(ob=self.myobject, mylist=self.objectItems())

and access the stuff within dtml.

<dtml-var "">

<dtml-in mylist>
<dtml-let x=sequence-item>
<dtml-var "x.myproperty">

as for the external method stuff, this is a guess. external methods are
just that. external methods. the global stuff isn't defined, they live
in a different internal namespace than a python product or your zope
objects, you can access zope objects through self which is the only hook
general hook back into zope and pass objects explicitly to the doc



Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to