RE: [Zope] Questions about DocumentTemplate.
Hi Mark. I've cc'ed this to the zope list, since others may find this useful.
I want DocTemplate to expose an object model, and it seems perfect for the task. However, Im having trouble using "." expressions.
Code speaks louder than words, so my code is: ## class Spam: def eggs(self): return "Eggs"
spam=Spam()
from DocumentTemplate import * ss=HTML('Eggs are <!--#var expr="spam.eggs()"-->') print ss(spam=spam)
ss=String('Eggs are %(spam.eggs)s') print ss(spam=spam) ##
What Im hoping to do should be quite obvious - I want to refer to "spam.eggs" in the DTML.
With the HTML example, #var expr="spam.eggs()" is the best I can get. It seems ugly to me, and I feel there must be a better way.
The <!--#var expr="spam.eggs()"--> is a perfectly valid way to do it. Another way would be to use the "with" tag: <!--#with spam--> <!--#var eggs--> <!--#/with--> Neither is really "more correct" than the other, though the with construct is probably cleaner in situations where you use many services of the object: <!--#with spam--> <!--#var eggs--> <!--#var method_one--> <!--#var method_two--> <!--#var method_three--> <!--#/with-->
Using the String example, I can't make _anything_ work.
Any I missing something? Is there something I can do so that String('Eggs are %(spam.eggs)s') does what I want?
Hmm - it appears that the expr support is currently broken for the python string format syntax. We'll take a look at that. You can, however, also use the with construct here too: ss=String('eggs are %(with spam)[ %(eggs)s %(with)]') Just in case you hadn't found them already, the latest DTML manuals are on the zope site at: http://www.zope.org/Documentation/Guides/DTML. They contain some examples that try to demonstrate common DTML idioms. Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
participants (1)
-
Brian Lloyd