Re: [Zope] processing dtml in external method

2000-08-23 Thread Dieter Maurer

Scott Shepherd writes:
  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?
"evaluating dtml" means calling it.

The "__call__" of DTML methods, or, more generally, DocumentTemplates,
has two positional parameters, "client" and "REQUEST",
and an arbitrary number of keyword parameters.

"client" is "None", a single object or a tuple of objects,
"REQUEST" is "None" or a mapping, the keyword parameters
are anything.

The parameters determine, what bindings (i.e. name - value mappings)
are available in the DocumentTemplate's namespace.
If there are conflicts, the higher priority source wins.
The priority order is as follows (highest priority first):

  * keyword parameters
  * attributes of client
(I am not sure about the relative priority in the case
 of more than one clients. I believe to remember
 that later clients have higher priority)
  * the mapping.


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] processing dtml in external method

2000-08-22 Thread Kapil Thangavelu



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/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'...
 

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 "ob.id"

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

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
template.

etc.

Kapil

___
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 )