home
  • Blog
1.11
  • Getting Started
  • Concepts
  • The Object Model
  • Application
  • Templates
  • Routing
  • Components
  • Controllers
  • Models
  • Views
    • Introduction
    • Defining a View
    • Handling Events
    • Inserting Views in Templates
    • Adding Layouts to Views
    • Customizing a View's Element
    • Built-in Views
    • Manually Managing View Hierarchy
  • Enumerables
  • Testing
  • Configuring Ember.js
  • Cookbook
  • Understanding Ember.js
  • Contributing to Ember.js
Old Guides - You are viewing the guides for Ember v1.11.0.
Go to v5.0.0

Adding Layouts to Views

Edit pencil

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:

app/templates/my-layout.hbs
<div class="content-wrapper">
  {{yield}}
</div>

And then the following main template:

app/templates/has-a-layout.hbs
  Hello, <b>{{view.name}}</b>!

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

app/views/with-a-layout.js
export default Ember.View.extend({
  name: 'Teddy',
  layoutName: 'my-layout',
  templateName: 'has-a-layout'
});

This will result in view instances containing the following HTML

<div class="content-wrapper">
  Hello, <b>Teddy</b>!
</div>
left arrow
Inserting Views in Templates
Customizing a View's Element
right arrow
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2023 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue