Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Last active August 29, 2015 14:06
Show Gist options
  • Save knownasilya/25463f8cc7728d62b879 to your computer and use it in GitHub Desktop.
Save knownasilya/25463f8cc7728d62b879 to your computer and use it in GitHub Desktop.
Dynamic view binding helper for Ember.js
var DynamicView = Ember.ContainerView.extend(Ember._Metamorph, {
childViews: [],
viewChanged: function () {
var viewName = this.get('viewName');
var view = this.get(viewName) || this.container.lookup('view:' + viewName);
if (view) {
this.clear();
this.pushObject(view);
}
}.observes('viewName')
});
Ember.Handlebars.registerBoundHelper('dynamic-view', Ember.Handlebars.makeViewHelper(DynamicView));
{{dynamic-view viewName=myViewName}}
When `myViewName` changes, so does the view, if it's defined locally or if the container is aware of it.
{{dynamic-view viewName='login' login=controller.customLoginView}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment