RE: [Zope] is there a dtml-with convenience tag ?? or equivalent syntax
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
That was it!!!! thanks Dieter...I can wipe the blood from my dense...uh, dents in my head. ;) To wrap up my lesson for the thread. The answer is... <dtml-with expr="_.random.choice(folderwithmyZclasses.objectValues('myZclass'))"> <dtml-var myZclassmethod> </dtml-with> -Trevor Continuing thoughts: Should I assume there is no "one-liner" to do this? [Chris?] --1)A variable would have to be set in the middle of the argument while generating the random zClass and --2) get referenced again at the end as an attribute of the DTMLMethod. It might also produce code that is hard to read. sample attempt: (shows I still dont quite grasp how to use REQUEST beyond basics) <dtml-var expr="_.random.choice(folderwithmyZclasses."REQUEST.set('zi',objectValues('m yZclass'))".myZclassmethod(zi,_)"> Chris also suggested making a Python script from this... which could then pass a foldername, zClassname, and DTMLMethod. Cuz, I will prolly do this again. OR would this be better in ZPT? ... since it inserts random zClass content?
participants (2)
-
Dieter Maurer -
Trevor Toenjes