Rolilink
Rolilink

Reputation: 443

Underscore Template Error = Uncaught SyntaxError: Unexpected token ILLEGAL

var metrobusApp = metrobusApp || {Views:{},Models:{},Routes:{},JST:{}};
metrobusApp.JST["/main"] = _.template('
    <label>Introduzca el codigo de la tarjeta</label>
    <input type="text" id="txtCodigo"/>
    <input type="submit" id="btnSubmit"/>
    ');

metrobusApp.JST["/consultar/:id"] = _.template('
    <p>Id: <%tarjeta.get("id")%></p>
    <p>Saldo: <%tarjeta.get("saldo")%></p>
    <p>Estado de Contrato: <%tarjeta.get("estadoContrato")%></p>
    <p>Fecha y Hora: <%tarjeta.get("tiempo").fecha%> <%tarjeta.get("tiempo").hora%></p>
    ');

I am doing an app with backbone and phonegap. but first i want to test it in the browser then in the file of the templates this error appears: Uncaught SyntaxError: Unexpected token ILLEGAL

What i am doing wrong? the error appears at line 2.

Upvotes: 0

Views: 2933

Answers (1)

zerkms
zerkms

Reputation: 254886

In javascript you need to put \ in the end of each line of string literal in case if it is multiline

Like

metrobusApp.JST["/main"] = _.template('\
    <label>Introduzca el codigo de la tarjeta</label>\
    <input type="text" id="txtCodigo"/>\
    <input type="submit" id="btnSubmit"/>\
    ');

or you can split it to several concatenated strings like:

'foo' + 
'bar' + 
'baz'

Upvotes: 4

Related Questions