0
votes

I'm using underscore and backbone on a multi page site with a couple of underscore templates on each page. On my main view(cshtml) I load one javascript template like this http://cl.ly/GpFT and on my second view(cshtml) I use the same script setup but the javascript template is missing and then I get an error like this http://cl.ly/Gnrc

When I minify my scripts this will cause the script to abort. Is it possible to solve this in a nice way or do I need to load exactly the templates and scripts needed for each and every page?

1

1 Answers

0
votes

You don't tell us what your views look like so I'll assume that you're doing something like this:

var V = Backbone.View.extend({
    template: _.template($('#some-id').html()),
    //...
});

and your views are raising TypeErrors when you're loading them. If there is no #some-id in the DOM, then you'll be saying _.templates(null) and that doesn't make any sense. An easy way around this to compile the template in the view's constructor instead:

var V = Backbone.View.extend({
    initialize: function() {
        this.template = _.template($('#some-id').html());
        //...
    },
    //...
});