KOGI
KOGI

Reputation: 3989

Why won't my Ember template render?

Here's a fiddle for this question (add/remove single slash on line 5 and re-run)

Basically, two ways of binding (proper term?) my application template. I would expect both ways to work, but one works, and one doesn't.

Works

this.register( 'view:application',     Ember.View.extend());
this.register( 'template:application', Ember.Handlebars.compile( 'Hello, world!' ));

Broken

this.register( 'view:application', Ember.View.extend({
  'template': Ember.Handlebars.compile( 'Hello, world!' )
}));

This seems to be the case for all resources/routes, not just at the application level.

So, why doesn't the second method work?

Edit: Here's a another fiddle that shows a Handlebars view helper successfully using method 2 (broken) above. It seems it's only an issue for route views.

Edit 2: Thanks to c4p Here's an Issue on Github

Upvotes: 2

Views: 940

Answers (1)

mavilein
mavilein

Reputation: 11668

Have a look at this related question.

Short summary:

  • Ember expects to find templates in the global variable Ember.TEMPLATES. When you use Ember.Handlebars.compile, the compiled templates are put into the global variable Handlebars.templates.
  • If you want to use the compiling this way, you have to do something like this:

Ember.TEMPLATES['posts-template'] = Ember.Handlebars.compile('I am the template');
App.PostsView = Ember.View.extend({
    templateName: 'posts-template'
});

Upvotes: 1

Related Questions