# 템플릿에서 문자열이 같은지 확인하는 if 조건은 어떻게 작성하나요?

**URL:** <https://meta.discourse.org/t/how-to-have-if-string-string-in-template/158404>\
**Category:** Development\
**Created:** [7월 21, 2020, 4:11오후 UTC](https://meta.discourse.org/t/how-to-have-if-string-string-in-template/158404 "2020-07-21T16:11:34Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)\
**Post date:** [7월 21, 2020, 4:11오후 UTC](https://meta.discourse.org/t/how-to-have-if-string-string-in-template/158404/1 "2020-07-21T16:11:34Z")

</div>

플러그인에서 템플릿에 `if` 문구를 사용하여 문자열이 특정 값과 일치하는지 평가하고 싶습니다.

아래와 같은 형태입니다:

```
{{#each groups as |group|}}
  {{#if group.name === "AwesomeName"}}
      <div>There is a match!</div>
  {{/if}}
{{/each}}

```

Discourse에서 어떻게 해야 할까요?

* * *

Ember/Handlebars에서는 단순한 {{if}}가 작동하지 않는다는 것을 이해하고 있습니다. 헬퍼를 등록해야 하는 것 같습니다. 다음과 같은 방식으로요:

plugin/assets/javascripts/discourse/helpers/eq/js/es6

```
import { registerHelper } from 'discourse-common/lib/helpers';

registerHelper('eq', function(arg1, arg2) {
     if (arg1 === arg2) {
         return true
    } else {
       return false
    }
})

```

plugin/assets/javascripts/templates/components/my-component.hbs

```
{#each groups as |group|}}
  {{#eq group.name "AwesomeName"}}
      <div>There is a match!</div>
 {{/eq}}
{{/each}}

```

이것은 작동하지 않습니다. (에러 메시지가 표시되지 않습니다.)

[여기](https://meta.discourse.org/t/plugin-template-helper/51160)의 해결책도 시도해 보았는데, "makeBoundHelper"를 사용하려고 하지만 이 또한 저에게는 작동하지 않습니다. 해당 방법에서는 "makeBoundHelper"가 함수가 아니라는 에러가 발생합니다.

저는 단순히 문자열이 특정 값과 일치하는지 확인하는 if 문구를 사용할 수 있기를 바랍니다. 어떻게 해야 하나요?

---

_[View the full topic](https://meta.discourse.org/t/how-to-have-if-string-string-in-template/158404)._
