Templates.helpers.render()

render (name, context, options) Stringpublic

Defined in packages/ember-htmlbars/lib/keywords/render.js:14

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:

App.NavigationController = Ember.Controller.extend({
  who: "world"
});
<!-- navigation.hbs -->
Hello, {{who}}.
<!-- application.hbs -->
<h1>My great app</h1>
{{render "navigation"}}
<h1>My great app</h1>
<div class='ember-view'>
  Hello, world.
</div>

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.

<div class="author">
  Written by {{firstName}} {{lastName}}.
  Total Posts: {{postCount}}
</div>

You could render it inside the post template using the render helper.

<div class="post">
  <h1>{{title}}</h1>
  <div>{{body}}</div>
  {{render "author" author}}
</div>

Parameters:

name String
context Object?
options Hash

Returns:

String
HTML string
doc_EmberJs
2016-11-30 16:53:37
Comments
Leave a Comment

Please login to continue.