[Zope] quote escaping in DTML
Thomas B. Passin
tpassin@mitretek.org
Wed, 20 Feb 2002 16:18:26 -0500
I wrote:
>
> But you don't need to put a <dtml> tag inside another one (and it doesn't
> work). Just refer to the variable or expression that you would are
tempted
> to put inside a <dtml> tag, and don't use the inner tag.
>
> In this case, I assume that MM_swapImage() and MM_swapImgRestore() are
> functions that the browser will call, not expressions for Zope to
evaluate.
> It seems the easiest and clearest to build the problem string separately.
>
> Thus (I have added a few spaces so you can see where the double quotes
are),
>
> <dtml-let mouseover=" 'MM_swapImage(fld,' + _.chr(34)+_.chr(34)+','+
> _.chr(34)+_.chr(34)+',0)' ">
> <dtml-var "tag(name=name, alt=name, onMouseOut='MM_swapImgRestore()',
> onMouseOver=mouseover)">
> </dtml-let>
>
Another way that is probably more readable to build the string is to
interpolate string pieces using the Python %s syntax:
<dtml-let mouseover=" 'MM_swapImage(fld,%s%s,%s%s,0)' %
(_.chr(34),_.chr(34),_.ch(34),_.chr(34))">
Cheers,
Tom P