[Zope] sql query results -> DTML method problem

Dieter Maurer dieter@handshake.de
Mon, 18 Dec 2000 21:23:47 +0100 (CET)


"Manuel Amador (Rudd-O) writes:
 > > #8 	<dtml-in expr=\"findClassTitle(code=52.139)\">
 > 
 > RING: dont do that, dtml wont work in python namespace
 > instead, remember that in python namespace all vars present in dtml namespace 
 > are inherited.
I do not see a reason, why not to use this
(except, that " should not be escaped, of cause).

 > do this:
 >  	<dtml-in expr=\"findClassTitle(code=_.(\'class_code\'))\">
 > the __.() construct is required since underscore arent allowed in python 
 > variable names. if the var was called classcode, you could do
"_" are allowed in Python names. They are treated in the same
way as a letter.

DTML restricts the use of "_":

  A name must not *START* with an "_" (unless it is the special
  name "_").
  Inside name, you can use "_" freely.

 >  	<dtml-in expr=\"findClassTitle(code=classcode)\">
 > dats it.
That said, you can also use:
    	<dtml-in expr="findClassTitle(code=class_code)">

 > > <dtml-in expr=\"findClassTitle(code=<dtml-var class_code>)\"> *** syntax
 > > error
I agree with Manuel:
  you cannot nest DTML.
And it is this nesting, that triggered his "RING: do not do that!"

Use:

     <dtml-in expr="findClassTitle(code=class_code)">

I.e. you can simply use the name of the variable.

Manuel is right, too, that DTML allows much more characters
in names than Python does. If you have a name with a character
forbidden in Python names, such as e.g. a "-", then you
can use "_[name]" or "_.getitem(name)" (as Manuel said).
It is only, that "_" (unlike "-") is allowed in Python names.



Dieter