Introduction to Helper Functions

Learn about helper functions and their types in Ember.

Overview

Helper functions are JavaScript functions that can be called from a template. Ember’s template syntax limits what can be expressed to keep the structure of the application clear. If we need to calculate something in JavaScript, we can use a helper function. We can write a custom helper or use the built-in helper that Ember provides.

A helper takes a parameter passed to the function and returns a value. Here’s how we use a helper inside a template:

<p>{{helper arguments}}</p>

Generating helpers

In Ember CLI, we use the following command to generate a helper:

ember g helper <helper_name>

This command will create two files:

  • It creates the <helper_name>.js helper file.

  • It creates the <helper_name>-test.js file, which is a test file for the helper.

The newly created helper function comes with some predefined boilerplate code:

Get hands-on with 1400+ tech skills courses.