Skip to content

Instantly share code, notes, and snippets.

@Darep
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darep/a007628593170e64d7a8 to your computer and use it in GitHub Desktop.
Save Darep/a007628593170e64d7a8 to your computer and use it in GitHub Desktop.
Ember.js dynamic component rendering
/**
Helper for rendering a component dynamically by supplying a name.
NOTE: Only works on Ember.js 1.9 and lower, does not work on 1.10+.
Ember 1.11 will have this feature built-in.
Usage: {{render-component widgetName someData=some.data}}
*/
Ember.Handlebars.registerHelper('render-component', function(context, options) {
var componentName = Ember.Handlebars.get(this, context, options);
var helper = Ember.Handlebars.resolveHelper(options.data.view.container, componentName);
if (helper) {
helper.call(this, options);
} else {
console.error('Component not found in {{render-component}}: ' + componentName);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment