1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ember.jsAdvent Calendar 2012

Day 14

Ember.js カスタムヘルパの作り方

Last updated at Posted at 2012-12-19

12/20追記
20日の記事で、データバインディング機能付きのカスタムヘルパの作り方を説明しています。こちらもご参照ください

Ember.jsのViewヘルパを自作することができます。
例えばこういうやつです。

{{highlight name}}

カスタムヘルパは以下のように実装します。

Handlebars.registerHelper('highlight', function(property, options) {
  var value = Ember.Handlebars.get(this, property, options);
  return new Handlebars.SafeString('<span class="highlight">'+value+'</span>');
});

このカスタムヘルパは以下のようなHTMLに展開されます。

<span class="highlight">Peter</span>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?