Working on a new theme but I need your Help Please

Moved Technical Support
  • Hello,

    I start working on a theme that should display each topic content below topic title and details in "Recet Topics" and "Category" pages. The theme make posts displayed like on facebook and twitter walls.

    My problem is that I cannot intill now understand how node.js server side passes datas variables to template and how it works on nodebb. Is some one here can give me some tutorials or something that can help me..

    For example I added this to category.tpl to display topic content post but nothing is displayed, it seems that the variable {topics.posts.content} is null :

    <div class="content">

    but if I write :

    <div class="content">

    I can see the title.

    How to passe topic post content to the category view in NodeBB ?


  • @kacemlight post content is not available on the category page api

    You can see what's available in the category page api for one of the categories in this community using this link

  • Yes I know. Is there a way to add post content to the category page API ?

  • @kacemlight You will have to modify core for that

  • @kacemlight

    You can modify the api data using the hook in the page's controller method.

    In your case,

    But it's not a simple task afaik. You'll need to pull the post data from the database yourself, filter it based on the users' privileges, and arrange it in the way you want. Basically everything that happens in the topic controller, but substituting the users' settings for your own.

  • @yariplus Thanks for your help. I think it will not be easy to do it.

  • I don't know yet how it really works, how server passe API data via template to client-side. Has someone here a tutorial or something that can help me ?


  • You should look at how plugins do it, because you have to do the same.

    In your plugin.json, you need to add a library file and a hooks array. Create the library file and in it define the hook function. The hooks that you want likely end in .build, but not all pages have a build hook. The function gets passed an object with a templateData member object. You modify templateData and pass back the original object. Whatever you add to templateData is exposed in the template. e.g...

    // plugin.json
    	"id": "nodebb-theme-persona",
    	"scripts": [
    	"library": "library.js",
    	"hooks": [
    		{ "hook": "", "method": "filter_category_build" }
    // library.js
    module.exports = {
    filter_category_build: function (data, callback) {
    	console.dir(data.templateData); // See what's inside.
    	data.templateData.banana = "Best Fruit"; // Add some data.
    	callback(null, data); // Send it back.
    // category.tpl
    {banana} // Prints "Best Fruit"

    If you want to pass an array (such as for attaching posts data), you also have to make sure you use <!-- BEGIN -->, e.g.

    data.templateData.fruits = [
    	{ color: "red", fruit: "apple"},
    	{ color: "yellow", fruit: "banana"}
    <!-- BEGIN fruits -->
    <p> {fruits.color} {fruits.fruit} </p>
    <!-- END fruits -->
    // Prints:
    // red apple
    // yellow banana
  • @yariplus said:


    Thank youuuu I finally start understanding how it works. I'm not good at Node.js and js Frameworks. But I'm an expert JEE and web architecture. I wish that I could catch up..

Suggested Topics