Modify topic title



  • Hi everyone,

    I started writing a plugin for nodebb and started with the documentation. Unfortunately, it does not give much information about the nodeBB library. The only thing I could find was a list of all hooks (with broken links and no documentaton).
    So my first question is: Where can I find a documentation describing the the hooks and the documentation about async, meta etc.

    I want to add something to the topic header. So for example you have the thread title and below the date and the author ... how can I add a third label next to the author (also seperated with a point from the other informations)?
    I created a method getTopics (for the hook filter:topics.get) and I found out I can modify the title with topic.title ... But I haven't find a way to access the information below the title.

    Thanks!


  • Global Moderator

    Unfortunately there isn't much documentation for plugin APIs and whatnot.

    But to accomplish what you want, you will need to modify the topic template and add a new property to the topic objects in filter:topics.get as you're already kinda doing.



  • Thank you for your help! The nodebb team definitly should do more work on the documentation, so the community can make better plugins.

    I don't understand how I add a new property to the topic object.

      { "hook": "filter:topics.get", "method": "getTopics" },
    
    plugin.getTopics = function(data, callback) {
      var topics = data.topics;
    
      async.map(topics, function (topic, next) {
    		topic.title = '<span class="Label">Label </span>' + topic.title;
    		return next(null, topic);
    	}, function (err) {
    		return callback(err, data);
    	});
    };
    

    This will add Label in front of each Thread title. But I really have no idea how to append label (separeted with a point) in the row below the title next to the date and name of the author. I tried to find a definition of the properties of the topic object, but couldn't find anything (except from title). Could you show me a small example?


  • Global Moderator

    Like I said, you have to modify the topic template in addition to adding the data you want.

    Here's how to fix your hook method:

    plugin.getTopics = function (data, callback) {
      async.each(data.topics, function (topic, next) {
        // `topic` is the topic object
        // `label` is a new property
        topic.label = 'Label';
        next();
      }, function (err) {
        callback(err, data);
      });
    };
    

    Then you want to copy templates/partials/topics_list.tpl from the Persona theme into your plugin, with the same directory structure. Then add the element <span class="label">{topics.label}</span> in that template where you want it to go.



  • Thank you very much for your help, I actually understand now how this complete thing works although I wondered if this is a good ideabecause if there is any update to the theme this part will not get updated, right?

    As you said I created from my project folder the file templates/partials/topics_list.tpl and used the content from https://github.com/NodeBB/nodebb-theme-persona/blob/master/templates/partials/topics_list.tpl

    Then I tried some different changes for example in line 63 I added some more bullets after the tags.

    <small>&bull;</small>
    <small>&bull;</small>
    <small>&bull;</small>
    

    Exspecting that there would be three bulls between the tags and the timestamp.

    More over I added also the following to plugin.json

    "templates": "./templates"
    

    There hasn't changed anything. I had the same problem when I tried to create a settings page. For some reason nodebb seems to ignore everything in templates. I did not get any warning when running ./nodebb dev

    Edit: I opended it in the developer console and it was the orginal file and not my modified one. This confirms my theory that nodebb does not take my templates (in general?).


  • Global Moderator

    Did you run ./nodebb build -d before starting?



  • @PitaJ said in Modify topic title:

    ./nodebb build -d

    I didn't and it helped 😉
    So just in case what steps to I have to to when I do what changes?

    I currently use npm link for my plugin. I tested that I just have restart nodebb if I make changes to the json files oder js files. For this templates file I needed to link everything again and run this command. Why is this so? Do I have to this every time I add a new file in templates/ every time I do a change in this template file?


  • Global Moderator

    You shouldn't need to link again, you should only have to run ./nodebb build -d && ./nodebb dev after you make a change.

    You can also use grunt to automatically build and restart after making changes.


Log in to reply
 

Suggested Topics

  • 3
  • 3
  • 10
  • 5
  • 1
| |