[Zope] Newbie: Missing a Variable (TAL/METAL Question)
dieter at handshake.de
Sat Jul 29 16:01:47 EDT 2006
beno - wrote at 2006-7-29 10:09 -0700:
> <tr tal:repeat="item batch">
> <tal:block define="global number repeat/item/number">
> <td tal:content="number">1</td>
> <td tal:content="item/title">title</td>
> <td><tal:content metal:use-macro="here/?number/macros/author">author</tal:content></td>
> <td><tal:content metal:use-macro="here/?number/macros/content">content</tal:content></td>
> <td tal:content="item/bobobase_modification_time">
> modification date</td>
> Sorry, a site error occurred.Traceback (innermost last):
> Line 22, Column 8
> Expression: standard:'here/?number/macros/author'
> Module Products.PageTemplates.Expressions, line 107, in _eval
>TypeError: iteration over non-sequence (Also, an error occurred while attempting to render the standard error message.)
This one is a bit more difficult: you need to look at the source code
to find out what goes wrong.
The traceback again tells you that the problem is
Moreover, it tells you that the exception is raised in line 107
of "Module Products.PageTemplates.Expressions".
The code, you see there is "path[i:i+1] = list(val)".
I see from this code (it is okay when you do not yet see it),
that "list(val)" is the problem.
You must now look a bit around and take names seriously.
The code aroung is:
path = list(path) # Copy!
for i, varname in self._dp:
val = vars[varname]
if isinstance(val, StringType):
path[i] = val
# If the value isn't a string, assume it's a sequence
# of path names.
path[i:i+1] = list(val)
This loop is responsible to replace the "?varname" occurrencies in your
path by the value of the variable "varname".
As you see, the value may either be a string or a sequence of paths.
In your case, it is an integer and "list(<some_integer>)" results
in the "TypeError" you observe.
Add "number python:`number`" after your definition of "number", i.e.
<tal:block define="number repeat/item/number; number python:`number`">
I removed the "global" (as you no longer need it due to the introduction
The "`...`" is a Python operator equivalent to
a call to "repr(...)" which converts into a string.
More information about the Zope