New Settings Framework

NodeBB Development
  • Plugin & Theme Dev

    Since many plugin devs may not have noticed the new utility I recently added (PR) to the core that may be helpful to plugin devs, here a short brief:

    I've added a new Settings-Framework that provides the possibility to save whole objects within the database (gets stringified behind the scene).
    The object-structure gets updated whenever it and the version (provided within server-side constructor) change without any work on your side.
    Related to the server-side settings-module you can refer to the single (nested) object-attributes within client-side ACP templates.
    The new client-side settings-methods are settings.sync and settings.persist rather than the old settings.load and (left there for backwards compatibility).
    Build-in support for many input-types, arrays, selects, textareas, keyboard-keys but easy to expand with your own object-/input-types.

    If you come across an common used field-type you may create a new PR to get it into core 🙂
    (e.g. radio-button support is missing I just realize)

    For a whole (at least more complete than above) overview about what I'm talking see the docs 😉

    As always you have the choice (except you're using windows 😛 ) to put your complaints below or at /dev/null

  • #2


    Could this, in theory, be used to say, allow someone to pick their own theme❓ 🙂

  • Plugin & Theme Dev

    @a_5mith Nope 😛 It's just a more powerful way for plugin devs to save the admin-settings in database 😉

  • #4

    @frissdiegurke Awhhh. 😞 Good job either way buddy. 👍

  • Plugin & Theme Dev

    Looks like I have a shitload of refactoring to do for the Shoutbox... Will start using this with the poll plugin though!

    Any plugins that already utilize this new framework that I can "steal" from? 😛

    Edit: nvm, didn't scroll down far enough.

  • Community Rep

    Hello @frissdiegurke,

    I've implemented the "new" (I guess, 7 months late) Settings framework in my plugin, but I don't seem to have it working all the way. I know something has been saved to the DB because the panel for my the imgbed's settings reflects it, but I'm still getting default values when I try to pull them out with settings.get()

    For example:

    var defaultSettings = {
    		booleans: {
    			hasMarkdown: true
    		strings: {
    			extensions: 'jpg,jpeg,gif,gifv,png,svg'


    $('#save').click(function(event) {
    			// TODO clean and organize extensions
    			settings.persist('imgbed', wrapper, function persistImgbed() {


    var	userExt = settings.get().strings.extensions;

    userExt still reflects the original defaults....

  • Plugin & Theme Dev

    If you're referring to the master-branch the problem is that you cache the value of

    var	userExt = settings.get('strings.extensions');

    (and some further operations) once at plugin-start and don't refresh those values after settings.sync(); (within a callback).

    So you need to re-calculate the regex variable within a callback for settings.sync.

Suggested Topics

| | | |