home
  • Blog
1.13
  • Getting Started
  • The Object Model
  • Templates
    • Handlebars Basics
    • The Application Template
    • Conditionals
    • Displaying a List of Items
    • Binding Element Attributes
    • Binding Element Class Names
    • Links
    • Actions
    • Input Helpers
    • Development Helpers
    • Rendering with Helpers
    • Writing Helpers
  • Routing
  • Components
  • Controllers
  • Models
  • Testing
  • Ember Inspector
  • Configuring Ember.js
  • Understanding Ember.js
  • Contributing to Ember.js
Old Guides - You are viewing the guides for Ember v1.13.0.
Go to v5.0.0

Handlebars Basics

Edit pencil

Ember.js uses the Handlebars templating library to power your app's user interface. Handlebars templates are just like regular HTML, but also give you the ability to embed expressions that change what is displayed.

Ember takes Handlebars and extends it with many powerful features. It may help to think of your Handlebars templates as an HTML-like DSL for describing the user interface of your app. And, once you've told Ember.js to render a given template on the screen, you don't need to write any additional code to make sure it keeps up-to-date.

Defining Templates

The first thing you should change is your application template that is created automatically for you and is displayed when your app loads.

Next, you can define templates in the app/templates folder. Remember from Naming Convetions that by default, a route will render a template with the same name as the route.

app/templates/kittens.hbs
<h1>Kittens</h1>
<p>Kittens are the cutest!</p>

If you would like to create a template that is shared across many areas of your site, you should investigate components.

Handlebars Expressions

Each template has an associated controller: this is where the template finds the properties that it displays.

You can display a property from your controller by wrapping the property name in curly braces, like this:

Hello, <strong>{{firstName}} {{lastName}}</strong>!

This would look up the firstName and lastName properties from the controller, insert them into the HTML described in the template, then put them into the DOM.

By default, your top-most application template is bound to your application controller. Note that this file is not shown by default because it is created behind the scenes by Ember CLI. To customize the controller, create the following file:

app/controllers/application.js
export default Ember.Controller.extend({
  firstName: "Trek",
  lastName: "Glowacki"
});

The above template and controller would combine to display the following rendered HTML:

Hello, <strong>Trek Glowacki</strong>!

These expressions (and the other Handlebars features you will learn about next) are bindings aware. That means that if the values used by your templates ever change, your HTML will be updated automatically.

As your application grows in size, it will have many templates, each bound to different controllers.

left arrow
Enumerables
The Application Template
right arrow
On this page

  • Defining Templates
  • Handlebars Expressions
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