Thanks, that works good. It also escapes any special characters in the
string, an added bonus.

The only case I found where a new format option would work better is if you
use the dtml-var size option to limit the size of the string. I will
continue to play with it and see what I come up with.

Perhaps an option to back_quote should be added to dtml-var to eliminate
somewhat hairy looking expressions like this (taken from my code):

        <dtml-var "`'(Back up to ' + title + ')'`">

I never thought I would use every type of quotation mark in a single
expression! 8^)


-Casey D.

-----Original Message-----
From: Duncan Booth [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 31, 2000 10:09 AM
To: Casey Duncan; [EMAIL PROTECTED]
Subject: Re: [Zope-dev] dtml-var tag suggestion

> 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"':
>[0].text = "<dtml-var title>";
> And you wind up with this rendered:
>[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:[0].text = <dtml-var "`title`">;

should (untested) give you:[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
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?

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to