[Zope] is there a dtml-with convenience tag ?? or equivalent syntax

Dieter Maurer dieter@handshake.de
Mon, 10 Sep 2001 23:13:39 +0200 (CEST)


Trevor Toenjes writes:
 > ******************************************
 > how-to generate a DTMLMethod for a random zClass in a folder?
 > ******************************************
 > > <dtml-with folderwithmyZclasses>
 > >   <dtml-var
 > expr="_.random.choice(objectValues('myZclass')).myZclassDTMLmethod
 > > (_.None,_)"
 > > </dtml-with>
 > >
 > This got me closer.  ;) However, I thought it acquired the namespace of the
 > randomly selected 'myZclass'.
 > NOW,
 > I am getting...
 >             Error Type: NameError
 >             Error Value: global name 'headline' is not defined
 > 
 > **"headline" is in the PropertySheet of 'myZclass'...which is called in
 > 'myZclassDTMLmethod'.
You are doing difficult stuff, too difficult to be described
in a book for starters....

You should keep in mind that a DTML method only knows what is
explicitly passed into it.
The above passes essentially "_", the current namespace.
But this does not contain your ZInstance.

You have two options:

    <dtml-with expr="_.random.choice(objectValues('myZclass'))">
      <dtml-var myZclassDTMLmethod>
    </dtml-with>

    This pushes your ZInstance onto the DTML namespace and thereby
    makes it avaiable in your "myZclassDTMLmethod".

or

    <dtml-let zi="_.random.choice(objectValues('myZclass'))">
      <dtml-var expr="zi.myZclassDTMLmethod(zi,_)">
    </dtml-let>
    
    This way, you pass in the context as "client" argument.


Dieter