Recently I experienced an unexpected result while trying to render a tuple of two items in a diml-method.
I brought the code down to its essence.
In a dtml method I have the following code:
<dtml-in "tupleTest()" prefix="v">
<p><dtml-var "v_item"> </p>
The sequence of tuples is prepared in a function:
"test with a list of tuples"
The result when viewing the diml method looks like:
[('a', 1), ('a', 2), ('b', 1), ('b', 2)]
The call to <dtml-var "tupleTest()"> correctly displays the list of tuples, but the dtml-in sequence only displays the second item of each tuple.
This happens only when the tuple consists of 2 items. When the number of items is higher, the tuples are correctly displayed, also in the dtml-in sequence.
(Response originally via
reply to this email).
> ... dtml-in treats lists of pairs specially ...
This is documented behavior.
I no longer know where the original documentation can be found
but I found in section "126.96.36.199.1" ("Iteration step variables")
> sequence-item, sequence-key
> Usually, sequence-item is the current object and sequence-key
> raises a TypeError exception. If, however, the current object
> happens to be a pair, i.e. a tuple with two elements, then
> sequence-key is the first and sequence-item the second element in
> the pair.
 refers to a footnote with the content "I think, this is
I did not find it either on https://zope.readthedocs.io. What I found there is: https://zope.readthedocs.io/en/latest/zopebook/AppendixA.html?highlight=sequence-key#current-item-variables which tells the same story.
Related: given the age and crappiness of DTML, better use ZPT for generating markupish content or Jinja templates instead. DTML has many design flaws.
In the past I kept that chapter under my pillow and I still have a copy in my archive, so I should have known and it is not unlikely that I once knew...
Chapter 3....one of the most important artifacts of Zope