From a02ae9bf8fbfcece60ae18713ce89837725e0de8 Mon Sep 17 00:00:00 2001 From: Matthew Wilson Date: Fri, 21 Aug 2015 12:44:44 -0400 Subject: [PATCH] [DOC release] Replace docs for render lost during 1.13 rewrite (cherry picked from commit a0db1ffb36bb968d379395113b977b07527c8f2c) --- .../lib/keywords/render.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/packages/ember-routing-htmlbars/lib/keywords/render.js b/packages/ember-routing-htmlbars/lib/keywords/render.js index 1b26abfc41d..c3e8af7f6ab 100644 --- a/packages/ember-routing-htmlbars/lib/keywords/render.js +++ b/packages/ember-routing-htmlbars/lib/keywords/render.js @@ -1,3 +1,8 @@ +/** +@module ember +@submodule ember-templates +*/ + import Ember from 'ember-metal/core'; // assert import { get } from 'ember-metal/property_get'; import EmberError from 'ember-metal/error'; @@ -7,6 +12,73 @@ import generateController from 'ember-routing/system/generate_controller'; import { generateControllerFactory } from 'ember-routing/system/generate_controller'; import ViewNodeManager from 'ember-htmlbars/node-managers/view-node-manager'; +/** + Calling ``{{render}}`` from within a template will insert another + template that matches the provided name. The inserted template will + access its properties on its own controller (rather than the controller + of the parent template). + If a view class with the same name exists, the view class also will be used. + Note: A given controller may only be used *once* in your app in this manner. + A singleton instance of the controller will be created for you. + Example: + + ```javascript + App.NavigationController = Ember.Controller.extend({ + who: "world" + }); + ``` + + ```handlebars + + Hello, {{who}}. + ``` + + ```handlebars + +

My great app

+ {{render "navigation"}} + ``` + + ```html +

My great app

+
+ Hello, world. +
+ ``` + + Optionally you may provide a second argument: a property path + that will be bound to the `model` property of the controller. + If a `model` property path is specified, then a new instance of the + controller will be created and `{{render}}` can be used multiple times + with the same name. + + For example if you had this `author` template. + + ```handlebars +
+ Written by {{firstName}} {{lastName}}. + Total Posts: {{postCount}} +
+ ``` + + You could render it inside the `post` template using the `render` helper. + + ```handlebars +
+

{{title}}

+
{{body}}
+ {{render "author" author}} +
+ ``` + + @method render + @for Ember.Templates.helpers + @param {String} name + @param {Object?} context + @param {Hash} options + @return {String} HTML string + @public +*/ export default { willRender(renderNode, env) { if (env.view.ownerView._outlets) {