2

Is there any way to reference an Ember view in the handlebars view helper without using the Ember Application global var? I'm getting the error below after precompiling my handlebars templates and minifying my Ember code using Grunt. This seems to be because the Ember global var is shortened to 'a' where the Handlebars template still refers to 'App.View'.

MyView.hbs:

{{#each controller}}
  {{view App.MyChildView}}
{{/each}}

MyChildView.hbs:

<div>Irrelevant HTML</div>

JS:

App = Ember.Application.Create();  
App.MyView = Ember.View.extend({...

App.MyChildView = Ember.View.extend({...

Error:

Uncaught Error: assertion failed: Unable to find view at path 'MyChildView'


Solution:

Found a solution to this by using the render helper instead of view.

MyView.hbs:

{{#each controller}}
  {{render "MyChildView"}}
{{/each}}
Michael Stone
  • 177
  • 1
  • 8

1 Answers1

1

The handlebars {{view}} helper can accept a string instead of a constant. So try:

{{#each controller}}
  {{view "App.MyChildView"}}
{{/each}}
Mike Grassotti
  • 19,040
  • 3
  • 59
  • 57
  • Does this still effectively reference the global Ember application variable (App) though? – Michael Stone Jun 20 '13 at 10:46
  • Yep. Agreed that's not ideal, would be nice if `{{view}}` did some kind of container lookup like `{{render}}`. Maybe it does I've not tried... – Mike Grassotti Jun 20 '13 at 15:26
  • Yeah it's a bit annoying, what I really need is a View (with the controller inheritance) but can't do the template name lookup like with render. – Michael Stone Jun 20 '13 at 16:14
  • It seems you're not the only one who wants this - stef just published a PR that would teach view helper about the container. https://github.com/emberjs/ember.js/pull/2961#issuecomment-20499040 – Mike Grassotti Jul 05 '13 at 03:42