Saving settings to v2 in my template file
-
@Jenkler Quickstart is set up to use settings v2 by default:
https://github.com/NodeBB/nodebb-plugin-quickstart/blob/master/static/lib/admin.js
-
Yes but i still need admin.js in my plugin folder. V1 works without any extra files at all. So i guess Nodebb core has no code for default plugin settings as v1 has.
<script>
require(['admin/settings'], function(Settings) {
Settings.prepare();
});
</script>There is no admin/plugin-settings by default.
-
hi, I mean someting like
<script>
require(['admin/settingsplugin'], function(Settings) {
Settings.prepare('pluginname');
});
</script>A default save system as with admin/settings but for plugin data save from the acp. the setting.prepare is nice but only works for config. it would have been nice to have plugin ssve as as core function of nodebb.
There may be many ways todo this but i hope you understand what I mean
or... maybe the same
Settings.prepare('config') and Settings.prepare() saves to config ... and
Settings.prepare('pluginname') saves to the plugin document and not config document.Improve the feat of Settings.prepare hehe
-
It is more complicated, but you don't need a separate file. Most of my plugins use something like this:
<script> require(['settings'], function (settings) { settings.sync('pluginname', $('form')) $('#save').click(function(event) { settings.persist('pluginname', $('form')) }) }) </script>
You need to make a settings object in your init. As well as use the
data-key=name
property in your inputs. -
@julian oh, dang. you're right. That's the only one I've ever used.
@Jenkler rainbows uses it.
https://github.com/yariplus/nodebb-plugin-rainbows/blob/master/public/templates/admin/plugins/rainbows.tpl#L144-L154
https://github.com/yariplus/nodebb-plugin-rainbows/blob/master/library.js#L61-L72 -
Thanks, i will take a look at it and howl if I get stuck