Last active
September 29, 2015 22:37
-
-
Save johanobergman/60483a8f49c30f245eef to your computer and use it in GitHub Desktop.
Sections in Ember.js components.
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
Simply register the two helpers "section" and "yield-section", and start right away! | |
See example below, using ember-cli: |
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
import Ember from 'ember'; | |
var section, yieldSection; | |
section = function(name, options) { | |
this.set(name + "Section", options.fn); | |
}; | |
yieldSection = function(name, options) { | |
var context, section; | |
if ((context = this.get('parent')) && (sectionBlock = context.get(name + "Section"))) { | |
sectionBlock(context); | |
} | |
}; | |
export { section, yieldSection }; |
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
import { section, yieldSection } from 'app-name/helpers/section-helpers'; | |
Ember.Handlebars.registerHelper('section', section); | |
Ember.Handlebars.registerHelper('yield-section', yieldSection); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment