Is 'post' the correct serializer to use when one wants to access extra data via decorateWidget with post-avatar:after?


(jezra) #1

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

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:

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.


#2

I think you will need:

api.includePostAttributes('foo');

(jezra) #3

Thank you! That absolutely did the trick!