[Zope] <dtml-var foo> vs. <dtml-var expr="foo()">

J. Cameron Cooper jccooper at jcameroncooper.com
Tue Jan 20 23:45:34 EST 2004


Juho Vuori wrote:

> A newbieish question. I thought <dtml-var foo> and <dtml-var 
> expr="foo()"> were the same thing. Seems they are not: Depending on 
> the way foo is called something differs in the environment they run in.
>
> Given the following situation:
>
> I have an dtml-method foo =
>  <dtml-var bar>
>
> And dtml-method bar
>  <dtml-var baz>
>
> Plus a third method baz
>  <p>Pazaa!</p>
>
> Now viewing foo does exactly what you think it does: It goes calls bar 
> which calls baz which returns the text <p>Pazaa!</p>
>
> Now change the first method foo:
>  <dtml-var expr="bar()">
>
> And you'll get KeyError: baz
>
> Does somebody understand what is going on?
>
> My real-world situation is that I need to specify a path, which as far 
> as I know forces me to use the expr="Pat.to.my.bar()" alternative. Or 
> does it not?

Part of the DTML magic is that it needs a namespace given to it. When 
you use the first syntax, this is done automagically. When you use the 
second, no magic is done, so you're required to do it. Take a look for 
documents explaining how to call DTML from ZPT for examples. (This sort 
of confusion is one of many reasons I will usually recommend against DTML.)

You can get a specific object's namespace on the top using dtml-with, btw.

          --jcc

-- 
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."





More information about the Zope mailing list