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

Handlebars 템플릿에는 기본적인 부울 논리만 제공됩니다. 이를 통해 속성에 대해 truthy 값을 확인할 수 있습니다.

더 복잡한 작업을 수행하려면 템플릿과 연결된 Ember JS 파일에서 논리를 처리해야 합니다.

예를 들어 templates/components/my-component.hbs에 템플릿이 있다고 가정해 보겠습니다. 계산은 components/my-component.js라는 JS 파일을 사용해야 합니다.

해당 파일에서는 다음과 같은 코드를 작성할 수 있습니다:

import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component";

export default Component.extend({
  @discourseComputed("string1", "string2")
  property(string1, string2) {
    return string1 === string2;
  }
});

property는 단순히 함수의 이름일 뿐이며, 다른 어떤 이름도 사용할 수 있습니다.

그런 다음 템플릿에서는 다음과 같이 작성합니다:

{{#if property}}
 blah blah...
{{/if}}

이것은 JS 파일에서 계산된 속성을 가져와 property가 true를 반환할 때만 #if 블록의 내용을 표시합니다.