Saving settings to v2 in my template file
-
This saves the settings for my plugin in v1 (config document)
nodebb-plugin-postlink/templates/admin/postlink.tpl at master ยท Jenkler/nodebb-plugin-postlink
A plugin that adds a prefix on postlinks. Contribute to Jenkler/nodebb-plugin-postlink development by creating an account on GitHub.
GitHub (github.com)
But I would like to save settings so its uptodate with latest standards. I guess settings:postlink should be the correct one in my case. I want to have minimal code and everyting in the template file.
Ist there any settings.prepare func for the newer settings framework.
@yariplus any tips?
To get the data I think i will use meta.settings.get. Can I use meta.settings.set in the tpl file?
Is there no default plugin settings in nodeBB
https://github.com/NodeBB/NodeBB/blob/master/public/src/admin/settings.js -
@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