[Zope] Method vs. Doc.

Daniel Fairs daniel.fairs@spiderplant.net
Tue, 5 Jun 2001 11:15:17 +0100


I write now with the knowledge of my "Newbie Acquisition Question"
question... :) Maybe this should be in the FAQ? (says he without checking
the FAQ ;)

A DTML Document is a 'proper' object. It has properties. It execuates in its
own context.
A DTML Method exectutes in the context of another object.

This is based on an example from the Zope book. Imagine you have DTML Method
called 'Feed' in the root folder.

Then you have a series of folders, 'Elephant', 'Tiger', 'Penguin' etc. under
the root folder. Inside each of these is a DTML Document, 'Dinner',
containing the name of the food that the animal in question likes to eat.
The Feed method in the root folder ir written to look at this 'Dinner' DTML
Document to find out the type of food to use.

OK, so now we can visit things like:

/Elephant/Feed
/Penguin/Feed

... and all is well. The 'Feed' method is being acquired from the root
folder *in the context of* the animal concerned.

So what happens if we change the 'Feed' DTML Method to a DTML Document?
Well, when we visit /Elephant/Feed we will find that suddenly Zope cannot
find the critical 'Dinner' DTML Document, because crucially, the 'Feed' DTML
Document will *execute in the context of the root folder*. It therefore
cannot acquire the 'Dinner' document, because it is executing 'higher up'
the hierarchy.

To conclude:
DTML Documents execute in a *fixed context* (the one they're created in)
DTML Methods can execute in *any context they're acquired in* (the object
they're called on)

Thanks to the two guys who replied to my previous mail and the authors of
the Zope Book who finally got my head round this :)

Hope that helps, and I hope I'm right! :)

Cheers,
Dan

_________________________________________________________________
Daniel Fairs | daniel.fairs@spiderplant.net | www.spiderplant.net