# 테마 컴포넌트에서 커스텀 필드에 어떻게 접근하나요?

**URL:** https://meta.discourse.org/t/how-do-i-access-custom-fields-in-a-theme-component/134701
**Category:** Development
**Created:** [11월 29, 2019, 11:23오전 UTC](https://meta.discourse.org/t/how-do-i-access-custom-fields-in-a-theme-component/134701 "2019-11-29T11:23:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [11월 29, 2019, 11:23오전 UTC](https://meta.discourse.org/t/how-do-i-access-custom-fields-in-a-theme-component/134701/1 "2019-11-29T11:23:20Z")

</div>

'[https://meta.discourse.org/t/our-solution-for-blurring-nsfw-content/124584’에서](https://meta.discourse.org/t/our-solution-for-blurring-nsfw-content/124584'%EC%97%90%EC%84%9C) 다음 코드를 사용하여 User Field 값을 접근했습니다. 하지만 더 이상 작동하지 않는 것 같습니다 - u.custom\_fields에 더 이상 데이터가 없습니다:

```plaintext
var u = Discourse.User.current();
if (u.custom_fields.user_field_2) {
    $('body').addClass('nsfw-always-show' );
}

```

최신 버전으로 업데이트하고 [safe mode](https://meta.discourse.org/t/53504?silent=true)에서 테스트해 보았지만 문제가 여전히 존재합니다:

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/9/79b8cfe60c6eda47f5e857b4c93aa0db22eb8ea2.png)

이 인터페이스에 변경 사항이 있었나요? User field에 접근하는 권장 방법은 무엇인가요?

최신 버전에서, 그리고 모든 플러그인과 테마를 비활성화한 [safe mode](https://meta.discourse.org/t/53504?silent=true)에서 테스트해 보았습니다.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [11월 29, 2019, 3:21오후 UTC](https://meta.discourse.org/t/how-do-i-access-custom-fields-in-a-theme-component/134701/2 "2019-11-29T15:21:18Z")

</div>

다음과 같은 방법을 시도해 볼 수 있습니다:

```html
<script type="text/discourse-plugin" version="0.8.27">
let currentUser = api.getCurrentUser();

if (currentUser) {
        api.container.lookup('store:main').find('user', currentUser.username).then((user) => {
        console.log('user', user.user_fields);
    });
}
</script>

```

`"text/discourse-plugin"` 스크립트 유형에 대한 자세한 내용은 [사이트 커스터마이징에서 PluginAPI 사용하기](https://meta.discourse.org/t/using-the-pluginapi-in-site-customizations/41281)를 참조하세요.
