# 当想通过 post-avatar:after 使用 decorateWidget 访问额外数据时，'post' 是正确的序列化器吗？

**URL:** https://meta.discourse.org/t/is-post-the-correct-serializer-to-use-when-one-wants-to-access-extra-data-via-decoratewidget-with-post-avatar-after/94249
**Category:** Development
**Created:** [2018年八月8日 21:32 UTC](https://meta.discourse.org/t/is-post-the-correct-serializer-to-use-when-one-wants-to-access-extra-data-via-decoratewidget-with-post-avatar-after/94249 "2018-08-08T21:32:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jezra](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jezra/32/105986_2.png) [@jezra](https://meta.discourse.org/u/jezra)
#### Post date: [2018年八月8日 21:32 UTC](https://meta.discourse.org/t/is-post-the-correct-serializer-to-use-when-one-wants-to-access-extra-data-via-decoratewidget-with-post-avatar-after/94249/1 "2018-08-08T21:32:12Z")

</div>

I was hoping to add information to posts in the plugin.rb file using `add_to_serializer`, and then access that data in my plugin’s default initializer file using `decorateWidget` from the api.

My plugin.rb contains

```plaintext
after_initialize do
  add_to_serializer :post, :foo do
    return "bar"
  end
end

```

From what I understand, the code _should_ be adding a ‘foo’ attribute (with a value of ‘bar’) to each serialized post.

My only javascript initializer contains:

```plaintext
import { withPluginApi } from 'discourse/lib/plugin-api';

export default {
  name: 'my-test',
  initialize() {
    withPluginApi("0.8.23", api => {       
      api.decorateWidget('post-avatar:after', helper => {
        console.log(helper.attrs);
      });
    });
  }
}

```

The admin plugins page shows that my plugin is installed, but when I view the output in my browsers console, I do not see the ‘foo’ attribute. Obviously, I’m doing something wrong, and I would greatly appreciate some knowledge.

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [2018年八月8日 23:08 UTC](https://meta.discourse.org/t/is-post-the-correct-serializer-to-use-when-one-wants-to-access-extra-data-via-decoratewidget-with-post-avatar-after/94249/2 "2018-08-08T23:08:08Z")

</div>

I think you will need:

```plaintext
api.includePostAttributes('foo');

```

> <https://github.com/discourse/discourse/blob/f7b4a2b3bac6d74b9b1949a8073f4a0314677388/app/assets/javascripts/discourse/lib/plugin-api.js.es6#L296-L310>

---

<div class="post-metadata">

### Author: ![jezra](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jezra/32/105986_2.png) [@jezra](https://meta.discourse.org/u/jezra)
#### Post date: [2018年八月8日 23:29 UTC](https://meta.discourse.org/t/is-post-the-correct-serializer-to-use-when-one-wants-to-access-extra-data-via-decoratewidget-with-post-avatar-after/94249/3 "2018-08-08T23:29:12Z")

</div>

Thank you! That absolutely did the trick!
