# 无法将“post-avatar”挂载到“topic-above-post-stream”插件出口

**URL:** https://meta.discourse.org/t/cannot-mount-the-post-avatar-on-the-topic-above-post-stream-plugin-outlet/269430
**Category:** Development
**Created:** [2023年六月23日 16:47 UTC](https://meta.discourse.org/t/cannot-mount-the-post-avatar-on-the-topic-above-post-stream-plugin-outlet/269430 "2023-06-23T16:47:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Adekunle\_Odujoko](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Adekunle\_Odujoko](https://meta.discourse.org/u/Adekunle_Odujoko)
#### Post date: [2023年六月23日 16:47 UTC](https://meta.discourse.org/t/cannot-mount-the-post-avatar-on-the-topic-above-post-stream-plugin-outlet/269430/1 "2023-06-23T16:47:05Z")

</div>

在阅读了本指南“ [初学者开发 Discourse 主题指南](https://meta.discourse.org/t/beginners-guide-to-developing-discourse-themes/93648) ”后，我尝试将 post-avatar 小部件挂载到帖子页面上的“topic-above-post-stream”插件出口，但它没有显示在页面上。

下面是我添加的代码：

```plaintext
<script type="text/x-handlebars" data-template-name="/connectors/topic-above-post-stream/post-page">
    <div class="post-detail">
      {{mount-widget widget="post-avatar"}}
    </div>
</script>

```

我是否遗漏了什么？

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [2023年六月23日 17:10 UTC](https://meta.discourse.org/t/cannot-mount-the-post-avatar-on-the-topic-above-post-stream-plugin-outlet/269430/2 "2023-06-23T17:10:01Z")

</div>

您可能缺少小部件显示所需的属性……例如，在此上下文中，它如何知道要显示哪个用户的头像？

查看原始小部件：

> <https://github.com/discourse/discourse/blob/96a2893284ed5488bbeb93463e40ed5b53084dd0/app/assets/javascripts/discourse/app/widgets/post.js#L195>

它需要：

- template
- username
- name
- url

因此，您需要将所需数据放入插件出口，然后将其传递给小部件……类似这样：

```hbs
{{mount-widget widget="post-avatar" args=(hash username=this.username)}}

```

话虽如此……您具体想实现什么？如果您只想显示头像，使用头像助手可能是一个更好的方法……看起来像这样：

```hbs
{{avatar user imageSize="large"}}

```

在这种情况下，您仍然需要确保 `user` 存在，因为这是它知道要显示哪个用户的方式。

---

<div class="post-metadata">

### Author: ![Adekunle\_Odujoko](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Adekunle\_Odujoko](https://meta.discourse.org/u/Adekunle_Odujoko)
#### Post date: [2023年六月26日 09:00 UTC](https://meta.discourse.org/t/cannot-mount-the-post-avatar-on-the-topic-above-post-stream-plugin-outlet/269430/3 "2023-06-26T09:00:34Z")

</div>

你好 @awesomerobot

谢谢你的回复，

我打算在帖子页面的每条帖子文本上方显示用户头像。但是我一直无法将所需的用户数据传入“topic-above-post-stream”插件出口。因此，在 common/head\_tag.html 文件中添加以下代码后，一个垃圾桶图标会显示在“topic-above-post-stream”插件出口上。

```plaintext
<script type="text/x-handlebars" data-template-name="/connectors/topic-above-post-stream/custom-post-page">
    <div class="post-detail header">
      {{mount-widget widget="post-avatar" args=(hash username=this.username)}}
    </div>
</script>

```
