Using Ember view helper in handlebars template with global var

1.5k Views Asked by At

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}}
1

There are 1 best solutions below

4
On

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

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