[Zope] testing with dtml-if

J Cameron Cooper jccooper at jcameroncooper.com
Thu Sep 4 21:08:39 EDT 2003


>>Does anyone know the syntax to use with dtml-if when i want to do something 
>>like this:
>>
>><dtml-if <dtml-var w>==1>
>>
>>do stuff
>></dtml-if>    ?
>>    
>>
This means, well, nothing. It's syntactically invalid. DTML is not a 
macro language, but an interpreted one, and the use of DTML inside a 
DTML tag is at best confusing and at worst a syntax error, and in no 
case is such a tag evaluated. The contents of a dtml-if can be either a 
name (without quotes) or a python statement (inside quotes, perhaps 
preceded by 'expr='.)

In this case, you are asking dtml-if about the truth value of an object 
named '<dtml-var w>==1', which is not a valid name. Or, at least, since 
I haven't tried, it shouldn't be.

>How is that different from
>
>  <dtml-if expr="w == 1"> ...
>  
>
This is asking about the truth value of the Python expression 'w==1', 
which will be true iff the contents of the first thing in the DTML 
namespace stack (the request, parameters, properties, acquisition, dtml 
loops, defines, et al) with the name of 'w' is equal within the Python 
definition to the integer 1.

>or possibly
>
>  <dtml-if expr="`w` == 1"> ...
>  
>
This is asking about the truth value of the Python expression " 'w'==1 
", which means "the character 'w' is equal to the integer 1." This will 
never be true, since 'w' is not 1.

          --jcc

-- 
"Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."
(http://www.devx.com/java/editorial/15511)





More information about the Zope mailing list