[Zope] "Computed" variable access (was: [Zope] use properties to get an object with dtml-var)

Dieter Maurer dieter@handshake.de
Tue, 15 Aug 2000 10:53:12 +0200 (CEST)


Gerard Metrailler Jr. writes:
 > Hello,
 > 
 > I am trying to get the following more generic.
 > 
 > <dtml-var "content.whos_who.gmetrail.real_name">
 > 
 > In that case, content and whos_who are folder, gmetrail is a ZClass I 
 > created which derivates from Image and real_name is a property of that object.
 > 
 > What I am trying to do is getting something like:
 > 
 > <dtml-var "user_info + REQUEST.AUTHENTICATED_USER + real_name"> where 
 > user_info is a property that I defined in /
You do not want to access a fixed variable but want the variable
to be accessed computed in some way.

Computed variable access is provided by

	"_[expression]"

Sometimes, you must use:

	"_.getitem(expression)"


Both forms evaluate "expression" into a variable name
and look it up in the namespace resulting in an object.
The first form calls the object, if it is callable, and returns
the result of this function call.
The second form always returns the object itself without
calling it.

For a DTML document/method "calling" means rendering, thus
the result is a string.


There is a related need: computed attribute access.
Here, an attribute to be accessed is not fixed but
must be computed.

You would use "_.getattr(object,expression)" in this case.



Dieter