How to create a 'subscribe to board' button
I have found this info on Create an email subscription to a board ... but I don't understand how to make use of it. I wish to add a button to certain boards that will allow users to subscribe to the board. I plan to create a custom component to place on the forum page with some conditional logic to display or not based on the board ID. This is (mostly) for private boards with small user numbers. I have also tried using this from board.subscribe:
This is beyond me - I am still learning the intricacies of Lithium code! I cannot translate the technical advice into a working solution. Can anyone help please?
You don't need to change the permissions in to your community.
Simplest way to do this in your community is to add below code to your to lithium endpoint.
<#assign board_ID= http.request.parameters.name.get("forumId") /> <#assign subscribed=restadmin("/boards/id/${board_ID}/subscriptions/users/self/add?subscription.type=email")/>
and use below Freemarker and Jquery code into your custom component and add this to your page.
<#assign boardID = coreNode.id />
<button id="subscribe">Subscribe to this board</button>
<@liaAddScript>
(function($) {
$('#subscribe').on('click', function() {
$.ajax({
url: "/community/plugins/custom/community/community/endpoint_name",
data: {'forumId':${boardID}},
method: "POST"
}).done(function(response) {
// DO SOMETHING HERE
}.fail(function() {
// DO SOMETHING HERE
}));
});
})(LITHIUM.jQuery);
</@liaAddScript>and You can also modify the same code to Unsubscribe the board by changing "Id" selector of button in HTML and jQuery and use unsubscribe API call in endpoint .