Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

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

Open
benshine opened this issue Dec 30, 2014 · 1 comment
Open

Comments

@benshine
Copy link

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
Copy link
Author

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' }));
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant