omppatil
(Om Patil)
November 28, 2023, 12:34pm
1
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.
Lilly
November 28, 2023, 12:41pm
2
Hi @omppatil perhaps this post might help you get in the right direction:
If you want to add a button to the post menu then you’ll need something a little bit different since posts are widgets .
You would need to add something like this to your theme / plugin.
api.addPostMenuButton("my-button", () => {
return {
action: "someAction",
icon: "someIcon",
className: "someClass",
title: "some title",
};
});
The plugin API has a method for adding new buttons that makes this relatively easy.
https://github.com/discourse/discourse/blob/7a2e8d3ead63c7d99e…
Also if you are new to Discourse plugin programming:
I’ve only just started but here’s my ‘starter for 10’ to get you going:
Read:
these
this
Try and read the code on the simplest, but popular plugins and see if you can understand what they are doing (this is not always easy, especially with the complexity of dealing with multiple files and the sometimes brutal functional brevity of javasctipt, but persevere)
You need to learn:
Lots of Javascript (look no further than @mpj ’s Fun Fun Function excellent & fun (!) videos (thanks man!))
Lots of …
There are a few ‘how to start’ guides for working with Discourse already and a wealth of useful info on meta, but I thought it might help to give an insight to the mental processes of starting from little, if any, prior coding experience to building substantial Discourse plugins.
Discourse is written by experienced developers and has a large codebase. This can feel intimidating. This intimidation factor can be a significant barrier for novice developers. This is a kind of ‘psychological primer’…
2 Likes
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 . It would also be a good idea to follow the guides Lilly posted!
3 Likes
omppatil
(Om Patil)
November 28, 2023, 12:53pm
4
Therefore, what file structure should be implemented, and where should the above code be placed?
Lilly
November 28, 2023, 1:26pm
5
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:
This is a crash course in Discourse theme basics. The target audience is everyone who is not familiar with Discourse themes. If you’ve already used Discourse theme / theme components, this guide is probably not something you need to read.
What are themes and theme components?
A theme or theme component is a set of files packaged together designed to either modify Discourse visually or to add new features.
Let’s start with themes.
Themes
In general, themes are not supposed to be compatible …
So, you want to create Discourse themes? Not sure where to start? Or maybe you have created Discourse themes before, but want to learn how to do even more cool things. Well, you’ve come to the right place
Developer’s guide to Discourse Themes
Subjects include a general overview of Discourse themes, creating and sharing Discourse themes, theme development examples, searching for and finding information / examples in the Discourse repository, and best practices.
Prerequisites:
…
also, from the first link I posted:
3 Likes
system
(system)
Closed
December 28, 2023, 1:26pm
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.