[Zope] Difference between dtml-let & dtml-in

Lennart Regebro lennart@regebro.nu
Thu, 24 Jan 2002 08:57:22 +0100


From: "Gabriel Genellina" <gagenellina@softlab.com.ar>
> <dtml-in "restrictedTraverse(PathToSqlMethod)()">
>     <dtml-var AnyFieldName>,
> </dtml-in>
>
> So I need to call the SQLMethod explicitly, and then it returns a sequence
> that <dtml-in> can handle (at least, this is what I guess.)

That is correct.

Lets see what the above code does:

1. restrictedTraverse(PathToSQLMethod):
restrictedTraverse looks through the Zope DB and tries to find the object
specifieed and return it. In this case it is an SQL method.
2.():
You call the returned object. In this case it will make a SQL query and
return a list of records that you iterate over.

This is equivalent to:
<dtml-let sql="restrictedTraverse(PathToSqlMethod)">
<dtml-in "sql()">

As you see the difference between this and your original code is that you
had:
<dtml-in sql>
What you do here is that you give dtml the name of something (sql). If the
named object is callable, dtml will first call it, then use it. When you put
things in an expression, it will evaluate that expression, but it will not
call the result of the evaluated expression.
So, if you had written <dtml-in "sql"> it would try to iterate over the sql
method, instead of the sql methods result.