# 如何在hbr文件中使用user字段？

**URL:** https://meta.discourse.org/t/how-to-use-user-field-in-hbr-file/218066
**Category:** Development
**Created:** [2022年二月13日 23:05 UTC](https://meta.discourse.org/t/how-to-use-user-field-in-hbr-file/218066 "2022-02-13T23:05:00Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![th21](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/th21/32/211915_2.png) [@th21](https://meta.discourse.org/u/th21)
#### Post date: [2022年七月13日 05:52 UTC](https://meta.discourse.org/t/how-to-use-user-field-in-hbr-file/218066/3 "2022-07-13T05:52:31Z")

</div>

```plaintext

  version="0.8">
  const testComponent = require('discourse/app/raw-views/list/posts-count-column').default;
  testComponent.reopen({
    user: function() {
        return Discourse.User.current()
    }.property()
  });
</script>

```

我尝试使用 `repoen()` 来修改 `posts-count-column` 组件以传递 currentUser 值，如下面的示例所示，但遇到了错误。我认为也许只有特定类型的组件支持此方法？

> [@Johani](#):
>
> ```plaintext
> 
> version="0.8">
> const categoriesOnlyComponent = require('discourse/components/categories-only').default;
> categoriesOnlyComponent.reopen({
> isHomepage: function() {
> return !this.parentView.searchService.contextType
> }.property()
> });
> </script>
> 
> ```

我找到了另一种方法，通过从上到下覆盖来将 currentUser 值传递到嵌套的 hbr 中，通过添加 `{{raw "list/posts-count-column" topic=topic tagName="div" **user=user** }}` 来插入值

```plaintext

        data-template-name='mobile/list/topic-list-item.raw’>
        data-template-name='list/post-count-or-badges.hbr'
        data-template-name="list/posts-count-column.hbr"

```

emberjs 是否有像 vue 那样的 provide/inject 函数来将值传递到嵌套模板？我搜索了一下，但没有找到太多信息。对此有什么建议吗？

---

_[View the full topic](https://meta.discourse.org/t/how-to-use-user-field-in-hbr-file/218066)._
