user2200321 user2200321 - 7 months ago 100
Javascript Question

Multiline strings in Javascript

I have a "multiline" string in my database that looks something like this:


I'm using Google's "Datstore" so it looks exactly like this in the viewer. There are no
's or things like that.

The problem is that when I try to set the retrieved string to a Javascript variable, I get an "ILLEGAL TOKEN" error. I'm setting it via Jinja2 so it looks like this:

var multilinestring = {{body|safe}}

I set other variables like this as well, but they are all integers or single line strings. Any help would be awesome!


If it's a multi line string, than you must have a new line character at the end of each line (e.g \n)

You can use the replace filter and see if you can remove the new line character e.g.

var multilinestring = {{body|safe|replace("\n", " ")}} // not tested