Old Guides - You are viewing the guides for Ember v1.10.0. VIEW v3.28.0
Edit Page

Adding Layouts to Views

Views can have a secondary template that wraps their main template. Like templates, layouts are Handlebars templates that will be inserted inside the view's tag.

To tell a view which layout template to use, set its layoutName property.

To tell the layout template where to insert the main template, use the Handlebars {{yield}} helper. The HTML contents of a view's rendered template will be inserted where the {{yield}} helper is.

First, you define the following layout template:

<script type="text/x-handlebars" data-template-name="my_layout">
  <div class="content-wrapper">

And then the following main template:

<script type="text/x-handlebars" data-template-name="my_content">
  Hello, <b>{{view.name}}</b>!

Finally, you define a view, and instruct it to wrap the template with the defined layout:

AViewWithLayout = Ember.View.extend({
  name: 'Teddy',
  layoutName: 'my_layout',
  templateName: 'my_content'

This will result in view instances containing the following HTML

<div class="content-wrapper">
  Hello, <b>Teddy</b>!