Add plugin settings
Let administrators change values of your plugin in Settings.
A plugin can add its own fields to the Settings screen with exports.config. Pluginable shows them in a group named after the plugin and saves them with the other settings.
1. Declare the settings
In the plugin index.js, add exports.config. Each item has an id, a name shown on the screen and a default value:
exports.config = [
{ id: 'orders_limit', name: 'Orders per page', value: 20 },
{ id: 'orders_email', name: 'Notification email', value: '' },
{ id: 'orders_open', name: 'Accept new orders', value: true }
];The type of the default value sets the field: a number gives a number field, text gives a text field and true or false gives a switch.
Settings of all plugins share one list, so start each id with the name of your plugin.
2. Read the values
In the code of the plugin, read a setting as CONF.<id>:
var limit = CONF.orders_limit;Until somebody saves a value in Settings, CONF.orders_limit holds the default from exports.config. After SUBMIT, it holds the saved value at once.
3. Restart and check
Restart Pluginable and open Settings. The group Orders shows the three fields. See Plugin settings.