Re: [htmltmpl] (no subject)
Brought to you by:
samtregar
From: Douglas K. <dlk...@rh...> - 2002-07-07 12:32:23
|
On Thursday 27 June 2002 09:59 pm, Glenn Morgan wrote: > Hi > > Had a search through the archive but can't find what I'm looking for, so > here goes. > > I am using HTML::Template with PageKit and having a problem with > <tmpl_var> substitutions in javascript quoted strings. See below: > > <button onclick="javascript: js_str='<tmpl_var > name="tmpl_str">;"></button> > > If tmpl_str="It's a wonderful life" > > Then my resultant html is > > <button onclick="javascript: js_str='It's a wonderful life'";></button> > > This is obviously broken due to the unescaped single quote in It's. The > same would apply if the js string assignment was enclosed in double > quotes and I included doulble quotes in my tmp_str value. > > What I really need to do is: > > tmpl_str=It\'s a wonderful life > > and all would be well. > > Unfortunately, > > 1) I am working with db data and am not aware of what chars data values > contain. > > 2) I am using the same data values in different places within the same > template and do not want escaped quotes in all cases. > > These two cases make it very messy to filter my datasets and escape > here, there and everywhere. > > Any ideas? Is there a simple solution or would a escape=quotes patch be > the way to go? > You need to filter the data looking for the character in the data stream. This is what I use to take care of that problem. $data =~ s|"|\\"|g; -- Douglas Kirkland Technical Support Department Rhyton Corporation te...@rh... http://www.rhyton.com |