[Zope] Nesting <dtml-in>

Sam Gendler sgendler@teknolojix.com
Fri, 05 Nov 1999 17:54:34 -0800


"David S. Harrison" wrote:
> 
> Is it possible to nest <dtml-in> constructs such that the inner
> structure still has access to the data in the outer structure?
> My reading of the DTML guide seems to indicate that the answer
> is no.  It appears that the name of the item for iteration
> is "sequence-item" at all levels.

I had this exact same problem this morning.  I finally solved it by
assigning the variables from the outer loop to new variables before
entering the inner loop.  For example:

<dtml-in some_sql_query>
  <dtml-let var1=some_sql_field1
            var2=some_sql_field2>
    <dtml-in some_other_sql_query>
      <dtml-if "some_other_sql_field==var1">
        Do Something
      </dtml-if>
    </dtml-in>
  </dtml-let>
</dtml-in

I actually wound up executing the inner query a single time and
assigning it to a variable <dtml-let queryResult=some_other_sql_query>
before entering the outer query.  This prevents the parser from having
to go to 
the cache for the query results (or worse, the database) during every
iteration of the outer loop.

--sam