Key-value tags for topics or posts

Plugin Development
  • I'm just getting started with nodeBB. I would really like to associate key-value pairs with topics. That is, I want to be able to tag a topic with things like "priority: low" or "prog_lang: julia". The only thing I found so far is

    Any thoughts about the feasibility of this would be appreciated.

  • Store the values in a database hash. Call it topic:{tid}:yourplugin, where {tid} is the topic id.

    The hash is a key-value store, so you would do,

    db.setObjectField('topic:{tid}:yourplugin', 'priority', 'low')

    to set a value. You do not need to define the object ahead of time.

    Now you probably want to add that data to the template vars so it can be displayed to the user, so hook into and add the values.

    plugin.topicBuild = function(data, next) {
      db.getObject('topic:' + data.templateData.tid + ':yourplugin', function (err, yourdata){
          if (err) console.log(err)
          if (err || !yourdata) return next(null, data)
          // Add your key-values to the template data.
          data.templateData.yourplugin = yourdata
          next(null, data)

    Now you will be able to see the data in your template using, e.g.

  • Oh, just realized you posted this in feature requests. This is more of a plugin thing. No way to do this in core.

  • Thanks, this is useful. I only posted under feature requests because I'm new and don't yet know how things work around here. I now know that this would have to be implemented as a plugin, and I suspect that it will not be too difficult. That is a lot more than I knew yesterday!

Suggested Topics