Permalink
Browse files

Merge pull request #688 from trek/DocumentationForYieldHelper

Adds documentation for {{yield}} Ember.Handlebars helper
  • Loading branch information...
2 parents 7a4fafb + c8a46bb commit 82a6a8d9ae68218374d205e4ac322666cb30bf31 @wagenet wagenet committed Apr 15, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 packages/ember-handlebars/lib/helpers/yield.js
@@ -1,5 +1,48 @@
var get = Ember.get, set = Ember.set;
+/**
+ @name Handlebars.helpers.yield
+
+ When used in a Handlebars template that is assigned to an `Ember.View` instance's
+ `layout` property Ember will render the layout template first, inserting the view's
+ own rendered output at the `{{ yield }}` location.
+
+ An empty `<body>` and the following application code:
+
+ AView = Ember.View.extend({
+ classNames: ['a-view-with-layout'],
+ layout: Ember.Handlebars.compile('<div class="wrapper">{{ yield }}</div>'),
+ template: Ember.Handlebars.compile('<span>I am wrapped</span>')
+ })
+
+ aView = AView.create()
+ aView.appendTo('body')
+
+ Will result in the following HTML output:
+
+ <body>
+ <div class='ember-view a-view-with-layout'>
+ <div class="wrapper">
+ <span>I am wrapped</span>
+ </div>
+ </div>
+ </body>
+
+
+ The yield helper cannot be used outside of a template assigned to an `Ember.View`'s `layout` property
+ and will throw an error if attempted.
+
+ BView = Ember.View.extend({
+ classNames: ['a-view-with-layout'],
+ template: Ember.Handlebars.compile('{{yield}}')
+ })
+
+ bView = BView.create()
+ bView.appendTo('body')
+
+ // throws
+ // Uncaught Error: assertion failed: You called yield in a template that was not a layout
+*/
Ember.Handlebars.registerHelper('yield', function(options) {
var view = options.data.view, template;

0 comments on commit 82a6a8d

Please sign in to comment.