dearmisterrobot
dearmisterrobot

Reputation: 164

Javascript unexpected token ILLEGAL in line-break

I render some data with Twig and do somethink like this:

var products = {
    {% for item in items %}
    {{ item.id }} : {
        'title': '{{ item.title }}',
        'info': '{{ item.info }}',
    }
}

There is an error, caused by line breaks in item.info variable.

I tried some tricks: replace \n\r to <br /> etc.

What should I do?

UPD #1

Error message: Uncaught SyntaxError: Unexpected token ILLEGAL

UPD #2

The replacement of \n and \r does without problems. The problem is that I need variable to be with line-breaks, not in one line.

Upvotes: 0

Views: 2444

Answers (1)

kehers
kehers

Reputation: 4170

Try end each line with a backslash i.e \ For example

console.log("Line\
New")

Upvotes: 2

Related Questions