yeoman / generator-backbone

Scaffold out a Backbone.js project
http://yeoman.io
638 stars 157 forks source link

Mustache templates don't render; they're just strings, not functions. #309

Open benshine opened 9 years ago

benshine commented 9 years ago

I created a new app using backbone-generator with --template-framework=mustache, then generated a view and tried to render it: yo backbone cats --template-framework=mustache yo backbone:view CatView

I changed the definition of render so that it doesn't try to look at a model, and removed the call to listen to the model in initialize, so I wouldn't need a model for this issue report. Now render is just:

render: function () {
    this.$el.html(this.template( { name: 'Fluffy' } );
}

In main.js, I created a single CatView and tried to render it:

 var catView = new Cats.Views.CatView({ el: '#theCat' });
 catView.render();

This fails, because this.template is just a string, not a function, so it can't be called. I think we just need to add a call to Mustache.render; I'll see if I can get this fixed.

benshine commented 9 years ago

Easily fixed: bower install mustache, include mustache.js in index.html, then change the render call to

    render: function () {
        this.$el.html(Mustache.render(this.template, { name: 'Fluffy' }));
    }