Samuel Lindblom
Samuel Lindblom

Reputation: 819

Ember.Handlebars.compile returns code instead of handlebars output

I have a view that looks like this:

App.StarRatingView = Ember.View.extend({
    template: function() {
        return new Ember.Handlebars.compile('test')
    }
})

This is supposed to insert test in the page, but instead it inserts the definition of the compile() function:

function (context, options) { options = options || {}; var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data); var compilerInfo = container.compilerInfo || [], compilerRevision = compilerInfo[0] || 1, currentRevision = Handlebars.COMPILER_REVISION; if (compilerRevision !== currentRevision) { if (compilerRevision < currentRevision) { var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision], compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision]; throw "Template was precompiled with an older version of Handlebars than the current runtime. "+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+")."; } else { // Use the embedded version info since the runtime doesn't know about this revision yet throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+ "Please update your runtime to a newer version ("+compilerInfo[1]+")."; } } return result; }

Any ideas why this is happening?

Upvotes: 0

Views: 253

Answers (2)

Jordy Langen
Jordy Langen

Reputation: 3591

It doesn't expect a function. This should do the trick

App.StarRatingView = Ember.View.extend({
    template: Ember.Handlebars.compile('test')
})

Or even better:

App.StarRatingView = Ember.View.extend({
    templateName: 'test'
})

Ember will now render the view using the given template name.

Upvotes: 1

CraigTeegarden
CraigTeegarden

Reputation: 8251

You can just set the template property to the contents of the compiled output:

App.StarRatingView = Ember.View.extend({
    template: Ember.Handlebars.compile('test')
})

http://emberjs.jsbin.com/uYOvUWU/1/edit

Also see the emberjs docs on using templates in views

Upvotes: 0

Related Questions