I have a model with attributes names like @id
, @type
, etc.
If I try to use <%= @id %>
in a Marionette.ItemView
template (with Underscore) I get
Uncaught SyntaxError: Unexpected token ILLEGAL
Using the syntax ['@id']
does not produce the expected result.
Do I have to override the serializeData
function?
Thanks
Underscore templates require JavaScript expressions inside
<%= ... %>
, the compiled template useswith
so you can usually reference object properties as though they were variables. Your problem is that@id
is not a valid JavaScript expression.So yes, providing your own
serializeData
to remove the@
s is probably your best bet. Another possibility would be to use thevariable
option with_.template
:Then you could use things like
<%= data['@id'] %>
; the problem is that getting this approach to work with Marionette might be more work than simply cleaning up the@
s in a customserializeData
method.