如何在 Discourse 插件的帖子菜单中添加切换按钮并为其实现一个动作?

Hi!,
I’m new to Discourse plugin making and would appreciate some help with adding a toggle button to the post menu and implementing its action in the plugin.

Hi @omppatil perhaps this post might help you get in the right direction:

Also if you are new to Discourse plugin programming:

2 个赞

Hi!

You can use addPostMenuButton

api.addPostMenuButton('coffee', () => {
 return {
   action: 'drinkCoffee',
   icon: 'coffee',
   className: 'hot-coffee',
   title: 'coffee.title',
   position: 'first'  // can be `first`, `last` or `second-last-hidden`
 };
});

Then you can add your action this way:

api.attachWidgetAction("post", "drinkCoffee", function () {
    //
}

EDIT: Got Lillian’d :smile:. It would also be a good idea to follow the guides Lilly posted!

3 个赞

Therefore, what file structure should be implemented, and where should the above code be placed?

Reading the above linked topics should answer your related dev questions. It’s possible you could achieve what you want with a theme component instead of plugin. Thus, I would also add these to your reading list:

also, from the first link I posted:

3 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.