[Zope-dev] dtml-var tag suggestion
   
    Duncan Booth
     
    duncan@rcp.co.uk
       
    Mon, 31 Jul 2000 16:08:48 +0000
    
    
  
> I have been using dtml to create dynamic JavaScripts for some forms I am
> creating. In doing this I came upon the standard problem of inserting
> strings containing double quotes into a JavaScript such as where title =
> '"Quoted String"':
> 
> form.select.options[0].text = "<dtml-var title>";
> 
> And you wind up with this rendered:
> 
> form.select.options[0].text = ""Quoted String"";
> 
Given that, like Python, javascript accepts strings either single or 
double quoted, you could try using backquotes to escape the 
string:
 form.select.options[0].text = <dtml-var "`title`">;
should (untested) give you:
 form.select.options[0].text = '"Quoted String"';
Provided title is a string, this will escape any quotes and, for that 
matter, unprintable characters, and wrap either single or double 
quotes round the outside. If title is a method then you need to call 
it first: <dtml-var "`title()`">
-- 
Duncan Booth                                             duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan