# How to register a helper in Discourse?

**URL:** https://meta.discourse.org/t/how-to-register-a-helper-in-discourse/41904
**Category:** Development
**Created:** [2016 年 4 月 1 日午後 6:09 UTC](https://meta.discourse.org/t/how-to-register-a-helper-in-discourse/41904 "2016-04-01T18:09:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [2016 年 4 月 1 日午後 6:09 UTC](https://meta.discourse.org/t/how-to-register-a-helper-in-discourse/41904/1 "2016-04-01T18:09:46Z")

</div>

I’m trying to figure out the best way to register a handlebars helper for my Discourse plugin.

I have an ajax call in my initializer that determines whether the currentUser is part of a particular group. If they are, then they get an extra nav item.

I wanted to do something like this in my hbs file for the nav:

```
{{#if customHelper}}
//show nav item
{{/if}}

```

My other theories on how to do this:

1. Keep the logic in the initializer and use jquery to append the item to the nav.
2. Create a component for the nav item to only be displayed given the aforementioned logic.

So do you think registering a helper is the best to go, if so how? Or are one of my other approached better.

Thanks for any help or advise!

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2016 年 4 月 4 日午前 9:05 UTC](https://meta.discourse.org/t/how-to-register-a-helper-in-discourse/41904/2 "2016-04-04T09:05:24Z")

</div>

What would `customHelper` do? Can’t you just do something like this instead?

in your initializer

```js
export default {
  initialize(container) {
    const user = container.lookup('current-user:main');
    Discourse.ajax("/some-url").then(result => user.set("isPartOfParticularGroup", true));
  }
}

```

and in your `.hbs` file

```handlebars
{{#if currentUser.isPartOfParticularGroup}}
   // your stuff
{{/if}

```

---

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [2016 年 4 月 4 日午後 5:23 UTC](https://meta.discourse.org/t/how-to-register-a-helper-in-discourse/41904/3 "2016-04-04T17:23:07Z")

</div>

Wow so simple and works perfectly!

---

<div class="post-metadata">

### Author: ![leog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leog/32/119839_2.png) [@leog](https://meta.discourse.org/u/leog)
#### Post date: [2020 年 9 月 26 日午後 8:53 UTC](https://meta.discourse.org/t/how-to-register-a-helper-in-discourse/41904/4 "2020-09-26T20:53:44Z")

</div>

このトピックを掘り起こすのは申し訳ありませんが、私の質問にぴったり当てはまります。

プラグインを作成せずにヘルパーを登録することは可能でしょうか？例えば、テーマの HTML の head または body セクションにあるスクリプトからなどです。

ご回答をよろしくお願いいたします！

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2020 年 9 月 27 日午前 7:33 UTC](https://meta.discourse.org/t/how-to-register-a-helper-in-discourse/41904/5 "2020-09-27T07:33:29Z")

</div>

はい、通常は[テーマコンポーネント](https://meta.discourse.org/t/developer-s-guide-to-discourse-themes/93648)を使用してそれを行います。
