[Zope] quote escaping in DTML

Milos Prudek milos.prudek@tiscali.cz
Wed, 06 Feb 2002 16:12:13 +0100


Is it possible to escape quotes in DTML?

There are situations where single and double quotes pile up in a manner
that makes expressions invalid.


Example: I need to generate the following programatically:

<img src="/images/on/usability" width="82" height="20" border="0"
name="usability" onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('usability','','/images/on/usability',0)">

First try is working but not very readable:

<img src=<dtml-var "images.on.usability" url> 
   <dtml-with "images.on.usability">
     height=<dtml-var height> width=<dtml-var width> border=0
     name=<dtml-var title_or_id> alt=<dtml-var title_or_id>
     onMouseOut="MM_swapImgRestore()"
    
onMouseOver="MM_swapImage('usability','','/images/off/usability',0)"
   </dtml-with>>

Second try, using image tag tag:

<dtml-with "images.on.usability">
  <dtml-let name=title_or_id>
    <dtml-var "tag(name=name, alt=name,
     onMouseOut='MM_swapImgRestore()',
    
onMouseOver='MM_swapImage('usability','','/images/off/usability',0)')">
  </dtml-let>
</dtml-with>

This does not work, because single quote levels fight each other. I
tried to substitute value of onMouseOver using
dtml-let="MM_swapImage('usability','','/images/off/usability',0)", but
that's not working either, because Zope tries to evaluate MM_swapImage
which is impossible to do because it's JavaScript code :-)

So elegance goes overboard and I stick with the first try. Is there a
cleaner way to do this?

--
Milos Prudek