如何在主题组件中访问自定义字段?

你可以尝试类似下面的代码:

<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