Hi This piece of code works fine: <dtml-let sql="restrictedTraverse(PathToSqlMethod)"> <dtml-in sql> <dtml-var AnyFieldName>, </dtml-in> </dtml-let> where PathToSqlMethod is a path to any SQLMethod, and AnyFieldName is a column name in that SQLMethod. Then, I didnt like the dtml-let, so I collapsed both lines, and wrote: <dtml-in "restrictedTraverse(PathToSqlMethod)"> <dtml-var AnyFieldName>, </dtml-in> and I got a KeyError in __getitem__, Error Value: 0 (zero). After several attempts I got the right way of doing it: <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.) But now, I don't understand why the ()'s arent needed using <dtml-let>, and then, why are them really necessary using <dtml-in "">. I would expect both tags to behave similarly. Perhaps someone can explain me the difference. Gabriel Genellina Softlab SRL
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.
At 08:57 24/1/2002 +0100, Lennart Regebro wrote:
<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.
Ah, thank you, I see now. This "auto-call" feature of DTML is very handy, I guess, but a bit confusing at first... Gabriel Genellina Softlab SRL
participants (2)
-
Gabriel Genellina -
Lennart Regebro