[Zope] First External Method
Thomas B. Passin
tpassin@mitretek.org
Tue, 23 Oct 2001 13:39:09 -0400
[Ben Ocean]
> At 06:43 PM 10/23/01 +0400, you wrote:
> >On Tue, Oct 23, 2001 at 07:31:21AM -0700, Ben Ocean wrote:
> > > > Do not use DTML inside DTML.
> > > > <img src="images/top" width=<dtml-var sizeCalc(1008,size)>...
> >
> > You should call it like this: <dtml-var "sizeCalc(1008, size)">. And
if
> >you receive an error about "size" - there is a problem with that size,
and
> >you should fix the problem with the size, not with the External Method.
>
> I'm confused. If I plug <dtml-var size> anywhere else in the above script
> it prints *1*. In other words, I have a dtml method called *size* and the
> only thing in it is the number 1. If I replace *size* with the number 1 in
> the above <img> tag, width yields 1008 as it should (1008*1). So I don't
> understand why the <dtml-var size> doesn't work when called as *size* in
> the External Method. What am I missing?
When you say <dtml-var size>, Zope discovers that "size" is an external
Python function and makes a Python call size() (simplified but close
enough).
When you say <dtml-var function_call(parm1,parm2)>, you get an error because
DTML does not understand the syntax,
Instead, you must write <dtml-var "function_call(parm1,parm2)">. When it
sees the quotation marks, Zope sends the quoted string to Python to be
evaluated, with some context information so Python can find the values of
Zope properties and variables. But Python isn't going to know to call a
Zope function to evaluate an External Method.
If Python can't evaluate one of the parameters because it is a DTML thing,
you can just evaluate it before calling the External Method, like this:
<dtml-let Size=size>
<dtml-var "sizeCalc(1008,Size)">
</dtml-let>
This way, Python has an ordinary Zope variable to find, which it can get
from the environment it receives.
Cheers,
Tom P