My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 65: Javascript within JSON templates
1 person starred this issue and may be notified of changes. Back to list
Status:  Done
Owner:  ----
Closed:  Nov 2011


 
Reported by ewan.duc...@gmail.com, Sep 2, 2011
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.

Nov 14, 2011
Project Member #1 andyc...@gmail.com
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 }.

Status: Done

Powered by Google Project Hosting