When using underscore templates, you need JavaScript expressions within <%= ... %>
. The compiled template utilizes the with
statement, allowing you to reference object properties as variables. However, the issue arises when trying to use @id
which is not a valid JavaScript expression.
To resolve this, it would be best to create your own serializeData
function to eliminate the @
s. Alternatively, you can utilize the variable
option with _.template
:
By default, template inserts values from your data into the local scope using the with
statement. However, you can specify a single variable name using the variable setting for faster rendering.
_.template("Using 'with': <%= data.answer %>", {answer: 'no'}, {variable: 'data'});
=> "Using 'with': no"
This allows you to access properties like <%= data['@id'] %>
; however, integrating this method with Marionette might require more effort than simply cleaning up the @
s in a customized serializeData
function.