[Zope] DTML equiv of eval (again).
Evan Simpson
evan@4-am.com
Sat, 02 Oct 1999 19:37:46 -0500
chas wrote:
> Just when I thought I understood how to use _['var' + x] as
> an equivalent of eval() within DTML, this one trips me up :
>
[snip]
> But this does not :
> <dtml-var "_['Images.img' + x]">
This would find a single object which has Id ('Images.img'+x). In fact,
one of the primary reasons for using _[''] notation in expressions is to
allow references to Ids with periods and other characters in them which
are not legal in Python identifiers. _[] is not like eval(), it's a
simple namespace lookup. The DTML equivalent of eval() is <dtml-var
expr="expression"> (no, I'm not kidding!)
In your case, you want either <dtml-with Images><dtml-var
"_['img'+x]"></dtml-with>, or my unreleased Product which allows
expressions like <dtml-var "_['Images/img'+x]">.