[Zope] YA newbie question

Tino Wildenhain tino@wildenhain.de
Fri, 09 Jun 2000 22:25:18 +0200


Hi Randy,

> ...
>    I figured this would be easy to do with Zope.  I created a subdirectory
> called "modules" and put some modules into that; for example, "leftbuttons"
> is a dtml method containing a table data block which contains the standard
> left menu button HTML.  I figured I could whip up a page and at the
> appropriate place in that page, do a '<dtml-var "modules.leftbuttons">' and
> have that code inserted into the page.
> 
>    That was my thinking.  "leftbuttons" views properly by itself.  However,
> when I try that dtml-var statment above, the page displays raw HTML.

try the following:
either:

<dtml-var "modules.leftbuttons()">

or:

<dtml-with modules>
<dtml-var leftbuttons>
</dtml-with>

the reason for this is: anything inside "" is a python expression,
meaning
it is interpreted as if you typed it into an running python-interpreter
(with the zope-context around, of course).
So python calls the ojects __repr__() method here to display it. For
string-like
objects __repr__==__str__ (with single quotes arount them)
For some zope objects "self-displaying" means showing their data as
source.

If you use <dtml-var > without the quotes, zope does do some magic with
the __call__() method of the object. Calling a dtml-method renders its
output
rather then the source.
This is what is done in the first variant.

NB: often you have to provide the documents context to the method, 
so the above call is somthing like <dtml-var
"modules.leftbuttons(_,_.None)">
(or such like - have to look again over some documentation or the list
for this)

HTH
Tino Wildenhain