Last active
August 29, 2015 14:17
-
-
Save Darep/a007628593170e64d7a8 to your computer and use it in GitHub Desktop.
Ember.js dynamic component rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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