0

Can anyone check my code? I don't know what happend but I got Uncaught SyntaxError: Invalid or unexpected token at one of my templates.

<script type="text/javascript" nonce="templates-random-id">
@templates.map { t =>
    $('#[email protected]').click(function() {
        document.getElementById('text').value = '@t.content';
    });
}</script>

I use it for loading a templates from database.

    @templates.map { t =>
<button type="button" class="btn btn-default" id="[email protected]">@t.template_name</button>
}

What i got from the source in browser:

$('#template-17').click(function() {
            document.getElementById('text').value = 'blablabla blablablablablab lablablablabl ablablablablabla;';
        });

Edit: I will try change '@t.content' to @t.content with `. Maybe it will help.

1 Answer 1

1

This is probably because of @t.content which contains special symbols. This fix might apply to your problem as well Escape a JavaScript string in Play 2.0 view?.

Sign up to request clarification or add additional context in comments.

1 Comment

@Html(t.content) might help as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.