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

您好!

我是 Discourse 插件开发新手,希望能得到一些帮助,在帖子菜单中添加一个切换按钮并实现插件中的相应操作。

你好 @omppatil,也许这篇帖子能帮助你找到正确的方向:

另外,如果你是 Discourse 插件编程新手:

2 个赞

你好!

你可以使用 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`
  };
});

然后你可以这样添加你的操作:

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

编辑:被莉莉(Lillian)抢先了 :smile:。遵循莉莉(Lilly)发布的指南也是个好主意!

3 个赞

因此,应该实现什么样的文件结构,以及上述代码应该放在哪里?

阅读上面链接的主题应该可以回答您相关的开发问题。您有可能通过主题组件而不是插件来实现您想要的功能。因此,我也会将以下内容添加到您的阅读列表中:

另外,从我发布的第一个链接中:

3 个赞

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