Using [backbone.js](http://backbonejs.org/) I'm trying to fetch a model from my server and based on that, render an underscore template. I first tried it without using the result of the api call using the following render function:

```
render: function(options) {
    this.ticketId = options.ticketId;
    var that = this;
    var ticketModel = new TicketModel({'id': that.ticketId});
    $.when(ticketModel.fetch()).done(function(){
        console.log(ticketModel); // this outputs the correct model
    });
    var template = _.template($('#tab-content-template').html(), {ticketId: that.ticketId});
    this.$el.html(template);
},

```

This works perfectly well. So I tried using the result of the api call to render the template:

```
render: function(options) {
    this.ticketId = options.ticketId;
    var that = this;
    var ticketModel = new TicketModel({'id': this.ticketId});
    $.when(ticketModel.fetch()).done(function(){
        console.log(ticketModel);
        console.log($('#tab-content-template').html());
        var template = _.template($('#tab-content-template').html(), {ticketId: that.ticketId});
        this.$el.html(template);
    });
},

```

but unfortunately, this results in an error saying

> 
> Uncaugt TypeError: Cannot read property 'html' of undefined.
> 
> 
> 

The weird thing is that it outputs the html in the console correctly resulting from `console.log($('#tab-content-template').html());`. The error I get is on the line which reads `this.$el.html(template);`

How can it be that it first is able to get the html(), and after that it says it can't find the property html? I'm totally stuck here.. :S

All tips are welcome!