[Zope] [SOLVED] Including Script-Generated String in Method Call

Dan Shafer dan@gui.com
Sun, 30 Dec 2001 18:16:32 -0800


Thanks to clues from Emmanuel Viennet and from Bak, each of whom 
supplied a piece of the puzzle, and to a more careful re-reading of 
Chapter 8 of The Zope Book, I finally fixed this problem. It turned 
out I had two compunding misunderstandings/errors.

First, to call the Python script in a DTML context, I needed the 
script to be in quotation marks (which I had) BUT I also needed the 
function parens for it to work.

Second, I learned the rule that you can't put DTML into a DTML tag. 
That was illuminating. It also helped me understand why the call to 
_render that Bak suggested wasn't working for me when I called the 
script but did work if I supplied a string.

So here is what I ended up with:

<dtml-let pagetoload="pagetoget()">
<dtml-var "_.render(_.getattr(PARENTS[0], pagetoload ))">
</dtml-let>

The Script Object ios called pagetoget. I assign its return value to 
the DTML variable pagetoload. Then I use pagetoload as an argument to 
the _.getattr builtin and pass the whole thing to _.render (which I 
didn't find documented anywhere but I'm grateful to you guys for 
pointing me to it) and, voila!, the page loads.

I'm going to write a HowTo on this one because I suspect it's 
something a lot of people have had to figure out the hard way. Now to 
figure out how to get a HowTo submitted on Zope.org.

Thanks again.

-- 
Dan Shafer, Author-Consultant
http://www.danshafer.com
http://www.shafermedia.com