mratmsf / json-template

Automatically exported from code.google.com/p/json-template
0 stars 0 forks source link

Javascript within JSON templates #65

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I have a template var index = jsontemplate.Template("<script 
type="text/javascript">function 
test(){alert('test')}</script><h2>{title}</h2>");
2. When loading the template the error "Uncaught SyntaxError: Unexpected 
identifier" is shown.

What is the expected output? What do you see instead? Should not error and have 
the function call test() available to call on the page. Instead it errors out 
due to the open braces in javascript "{". I have tried to use \u007B with the 
same result.

What version of the product are you using? On what operating system?
Windows 7,
Chrome 13.0.782.218,
json-template-0.8
jquery 1.5.1

Please provide any additional information below.

Original issue reported on code.google.com by ewan.duc...@gmail.com on 3 Sep 2011 at 3:53

GoogleCodeExporter commented 8 years ago
Sorry for the very late response -- there are a couple solutions:

1. Use {{}} or [] as your template delimiters.  (the "meta" option to the 
constructor)

2. If you split your JavaScript over multiple lines so that { and } don't 
appear on the same line it will parse.

3. Escape the {}.  {.meta-left} and {.meta-right} are { and }.

Original comment by andyc...@gmail.com on 15 Nov 2011 at 7:33