home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
1.13
  • Packages
    • ember
    • ember-application
    • ember-debug
    • ember-extension-support
    • ember-htmlbars
    • ember-metal
    • ember-routing
    • ember-routing-htmlbars
    • ember-routing-views
    • ember-runtime
    • ember-templates
    • ember-testing
    • ember-views
  • Namespaces
    • Ember
    • Ember.FEATURES
    • Ember.String
    • Ember.computed
    • Ember.inject
    • Ember.run
  • Classes
    • Ember.Application
    • Ember.Array
    • Ember.ArrayProxy
    • Ember.Binding
    • Ember.Checkbox
    • Ember.Component
    • Ember.ComputedProperty
    • Ember.ContainerDebugAdapter
    • Ember.Controller
    • Ember.ControllerMixin
    • Ember.CoreObject
    • Ember.DataAdapter
    • Ember.DefaultResolver
    • Ember.Error
    • Ember.Evented
    • Ember.Helper
    • Ember.InstrumentationSupport
    • Ember.Logger
    • Ember.Mixin
    • Ember.MutableArray
    • Ember.MutableEnumerable
    • Ember.Namespace
    • Ember.NativeArray
    • Ember.Object
    • Ember.Observable
    • Ember.PromiseProxyMixin
    • Ember.Route
    • Ember.Router
    • Ember.Service
    • Ember.Test
    • Ember.Test.Adapter
    • Ember.Test.QUnitAdapter
    • Ember.TextArea
    • Ember.TextField
    • Ember.VisibilitySupport
    • RSVP.EventTarget
    • RSVP.Promise

Class Ember.Helper public


Defined in: packages/ember-htmlbars/lib/helper.js:8
Module: ember

Ember Helpers are functions that can compute values, and are used in templates. For example, this code calls a helper named format-currency:

<div>{{format-currency cents currency="$"}}</div>

Additionally a helper can be called as a nested helper (sometimes called a subexpression). In this example, the computed value of a helper is passed to a component named show-money:

{{show-money amount=(format-currency cents currency="$")}}

Helpers defined using a class must provide a compute function. For example:

export default Ember.Helper.extend({
  compute(params, hash) {
    let cents = params[0];
    let currency = hash.currency;
    return `${currency}${cents * 0.01}`;
  }
});

Each time the input to a helper changes, the compute function will be called again.

As instances, these helpers also have access to the container an will accept injected dependencies.

Additionally, class helpers can call recompute to force a new computation.


Methods

compute (params, hash) public

Module: ember

Defined in packages/ember-htmlbars/lib/helper.js:77

params
Array

The positional arguments to the helper

hash
Object

The named arguments to the helper

Override this function when writing a class-based helper.

helper (helper) public

Module: ember

Defined in packages/ember-htmlbars/lib/helper.js:91

helper
Function

The helper function

In many cases, the ceremony of a full Ember.Helper class is not required. The helper method create pure-function helpers without instances. For example:

// app/helpers/format-currency.js
export default Ember.Helper.helper(function(params, hash) {
  let cents = params[0];
  let currency = hash.currency;
  return `${currency}${cents * 0.01}`;
});

recompute public

Module: ember

Defined in packages/ember-htmlbars/lib/helper.js:50

On a class-based helper, it may be useful to force a recomputation of that helpers value. This is akin to rerender on a component.

For example, this component will rerender when the currentUser on a session service changes:

// app/helpers/current-user-email.js
export default Ember.Helper.extend({
  session: Ember.inject.service(),
  onNewUser: Ember.observer('session.currentUser', function() {
    this.recompute();
  }),
  compute() {
    return this.get('session.currentUser.email');
  }
});
On this page


Methods

  • compute
  • helper
  • recompute
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 2025 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue Created with Sketch.