Problem with DTML and strings
Hello all: I'm trying to construct a dynamic string to get a name of an image based on the meta_type of a product... Here is the code (it must clarify what I'm saying... :-) <dtml-let nombre="_.string.join((_['meta_type'],'_img'))"> <dtml-var nombre> <img src="<dtml-var "images[nombre].absolute_url()">"> <dtml-var id> But this fails miserably... Zope says KeyError, but if a use a expression like this: <img src="<dtml-var "images['Disk_img'].absolute_url()">"> All works fine, and is the same string that 'nombre' contains What I'm doing wrong... -- Microsoft merges technologoies: Windows CE + Windows ME + Windows NT = Windows CEMENT ---- Antonio Beamud Montero Agora Systems S.A. http://www.agoratechnologies.com
How about <dtml-let nombre="meta_type + '_img' "> ? string.join uses a default separator of a space, so nombre is probably "Disk _img", note the space. -Paul Antonio Beamud Montero wrote:
Hello all: I'm trying to construct a dynamic string to get a name of an image based on the meta_type of a product... Here is the code (it must clarify what I'm saying... :-)
<dtml-let nombre="_.string.join((_['meta_type'],'_img'))"> <dtml-var nombre> <img src="<dtml-var "images[nombre].absolute_url()">"> <dtml-var id>
But this fails miserably... Zope says KeyError, but if a use a expression like this: <img src="<dtml-var "images['Disk_img'].absolute_url()">">
All works fine, and is the same string that 'nombre' contains
What I'm doing wrong...
Antonio Beamud Montero writes:
Hello all: <dtml-let nombre="_.string.join((_['meta_type'],'_img'))"> <dtml-var nombre> <img src="<dtml-var "images[nombre].absolute_url()">"> <dtml-var id>
But this fails miserably... Zope says KeyError, but if a use a expression like this: <img src="<dtml-var "images['Disk_img'].absolute_url()">">
All works fine, and is the same string that 'nombre' contains There probably is a small difference:
"join" separates the components through a space. Therefore, you get "Disk _img" rather than "Disk_img". Use "_.string.join((meta_type,'_img'),'')" (note the extra parameter to join, specifying an empty separator). Dieter
participants (3)
-
Antonio Beamud Montero -
Dieter Maurer -
Paul Erickson