Search code examples
templatesbackbone.jsunderscore.jsupgradeunderscore.js-templating

Template error upgrading to underscore 1.7


When upgrading my web app from underscore 1.6 to 1.7, I receive the following error "list is not defined". When using underscore 1.6 it works perfectly. Any ideas?

//acquire the list template
$.get('tpl/listTpl.html', function(templates) {

//run underscore js on the list template and pass in the full collection of models
var template = _.template(templates, {list:app.collections.list.models});

//load the underscore template into the DOM
that.$el.html(template);

});


Solution

  • From the 1.7.0 changelog:

    Underscore templates no longer accept an initial data object. _.template always returns a function now.

    You will need to change your code to the following:

    $.get('tpl/listTpl.html', function(templates) {
      var template = _.template(templates);
      var result = template({list:app.collections.list.models});
      that.$el.html(result);
    });