You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't need the HTML encode so I'm using the noEscape parameter because the compiledResult object is not used to compile any HTML template but only as server side object.
As you can see Handlebars works well in the case above but there are problems when there are characters that break the JSON.parse function as " or \n or \r.
You can see an example of scenario where it doesn't work:
I would not use Handlebars for such a use-case. Instead of generating a template with JSON.stringify it seems much easier and clearer to write a function like:
The performance should be better as well. You don't have to create a string first and parse it later...
If you still insist on using Handlebars...: There is no officially supported option to change the escaping-behavior of Handlebars (only noEscape), but you can hack it. Of course, hacking means that the hack may be broken in future versions. Here is an example that somehow works.
Hi there,
I'm using handlebars not for what it has borned but for compiling dinamically JSON.
In my case I have something like this:
I don't need the HTML encode so I'm using the
noEscape
parameter because thecompiledResult
object is not used to compile any HTML template but only as server side object.As you can see Handlebars works well in the case above but there are problems when there are characters that break the JSON.parse function as
"
or\n
or\r
.You can see an example of scenario where it doesn't work:
Do you have some suggestions about my case?
Mirko
The text was updated successfully, but these errors were encountered: