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.


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?

Thanks in advance