[Zope] Newbie still having problems understanding namespaces
J. Cameron Cooper
jccooper@rice.edu
Thu, 09 Aug 2001 15:02:53 -0500
>
>
><dtml-var expr="abs(-23)"> which I would have expected to evaluate to 23.
>
>Instead I get the error:
>
>Error Type: NameError
>Error Value: global name 'abs' is not defined.
>
>I guess this is because abs is not in the current nemespace. My question is
>where is the documentation that tells me which namespace to use and when?
>
Try
<dtml-var expr="_.abs(-23)">
which should work.
Why? Take this with a grain of salt, because I'm not certain I'll get it
correct:
When you use an expression, you are in the document's namespace. 'abs'
is a function in the DTML namespace (the namespace of DTML itself, not
an object using DTML.) To get DTML's namespace, which allows you to use
DTML things to get to the current object's namespace, you use the magic
underscore '_'. Thus you can get to DTML functions, use indexing to get
values, &c.
That's my best shot at explaining it. Of course, that's probably all
wrong. I just know how to do it, not necessarily how it works.
--jcc