Retrieve setting value from the client side
-
Hi, I just written the [nodebb-plugin-katex], and I'd like to change the delimiters inside the
formatting.addButtonDipatch
function in theclient.js
script here when the user change thedollarInline
setting inside the ACP.To do this, I need to get the value of the setting called
dollarInline
inside this client script. I know that I can retrieve this setting from the server side using:meta.settings.get('katex', function (err, options) { console.log(err, options.dollarInline); });
However, I can't figure out how I can get this value from the client side?
-
I'm not sure if I understood you correctly, but I think you want to use the PluginSocket (socket.io) for this:
Server:
https://github.com/rbeer/nodebb-plugin-smoothshorts/blob/master/smoothshorts_be.js#L60-L67
Client:
https://github.com/rbeer/nodebb-plugin-smoothshorts/blob/master/static%2Flib%2Fsmoothshorts_fe.js#L21-L24 -
Thank you @rbeer, with the help of your examples and th socket.io library I implemented it in this commit.
Here are some elements:
In the server side I've created a socket with a function to pass the desired config:
// Create a socket to pass config to the client-side PluginSocket.Katex = {}; PluginSocket.Katex.getConfig = function (socket, callback) { var data = { dollarInline: _self.config.dollarInline, }; callback(data); };
In the client side I retrieve the config from the socket using a jquert deferred.promise:
// Retrieve config from the plugin socket and then add the composer button var Katex = {}; var deferred = new $.Deferred(); function callBack(config) { Katex.dollarInline = config.dollarInline; deferred.resolve(config); } // do the async call to the socket. socket.emit('plugins.Katex.getConfig', callBack); ... // add the usd button to the composer when config caught from socket $.when(deferred).then(addComposerButton);