Skip to content

Plugin Development

Have a question about building a plugin? Ask here
424 Topics 1.9k Posts
  • 0 Votes
    2 Posts
    579 Views
    M

    After some more code digging and experiments I can answer my own question. A theme is a normal plugin and as such does not inherit any behavior from other plugins.
    So you need to copy everything you need from the base theme library.js to your child theme. And of course, you need to declare client scripts explicitly.
    Loading of missing templates from base theme is the only link between the base and the child theme.

  • Add functionality

    2
    0 Votes
    2 Posts
    258 Views
    phenomlabP

    @thanos6161 A bit like this ? https://phenomlab.com

  • 0 Votes
    1 Posts
    242 Views
    N

    Hi, I have following:
    {
    "hook": "filter:config.get",
    "method": "configGet"
    }

    My purpose is to use my own sort method for sorting topics in a category, automatically modifying visible "Sort By" html element with a special sorting method that I implemented, and make it selected automatically.

    I tried many hooks but "filter:config.get" was only one that is called before rendering or sending anything to client side. Other hooks such as "filter:categories.buildTopicsSortedSet", "filter:categories.getSortedSetRangeDirection","filter:category.topics.prepare", they all didn't work.

    For example, if I changed like following in a method for "filter:categories.buildTopicsSortedSet":
    data.settings.categoryTopicSort = 'most_myown';
    but in client side, it only shows the previous value of "data.settings.categoryTopicSort", not the value "most_myown".

    So I had to use "filter:config.get" because changing config there actually reflects to client side.

    To implement it, I first need to check information about category that the user just entered, and append it to config, and send it to client. They are supposed to be done in "configGet" method, which you see above. But I do not know how to get information about category that the user is in. I need to know about category info because my own sorting will only work for certain categories.

    Thank you very much.

  • This topic is deleted!

    1
    0 Votes
    1 Posts
    8 Views
  • 0 Votes
    4 Posts
    545 Views
    phenomlabP

    @magnusvhendin No problems. For clarity, once you have the plugin installed, you want this section

    b1d9072d-265a-486d-ae9b-f29d49fbed83-image.png

  • nodebb-plugin-question-and-answer

    Unsolved
    1
    0 Votes
    1 Posts
    306 Views
    S

    I have installed nodebb-plugin-question-and-answer v0.7.7 on nodebb v1.13.3. but when I post a topic as question, "mark this post as correct answer" is not available. "unsolved" tag is not appearing for topic which is posted as question. Please help me with this.

  • This topic is deleted!

    1
    0 Votes
    1 Posts
    1 Views
  • This topic is deleted!

    1
    0 Votes
    1 Posts
    3 Views
  • Get current user session

    18
    0 Votes
    18 Posts
    5k Views
    B

    THank you very much!

  • Social Sharing Buttons

    7
    0 Votes
    7 Posts
    2k Views
    G

    Social network share button is essential when I want to connect with social networks like facebook, whatsapp gb on WAGBPro

  • Get user votes based on category ID

    1
    0 Votes
    1 Posts
    214 Views
    M

    Hi, I wonder how can I get user votes based on category IDs?

  • Script to display all posts by _id

    4
    0 Votes
    4 Posts
    446 Views
    PitaJP

    @ape the standard way to get nodebb modules is require.main.require

    const Posts = require.main.require('./src/posts'); Posts.getPostData(pid, callback)
  • 0 Votes
    1 Posts
    583 Views
    dogsD
    This is just a little snippet.

    This is about the question How can I add custom data to a post? a small tutorial

    How to add custom data permanently to a post It will be saved into the object:

    You need the following hook:

    { "hook": "filter:post.create", "method": "postCreate" }

    This hook is fired, when a Post is created. So it contains RAW Data.

    A filter:hook like "hook": "filter:post.create" can be edited before beeing proceeded.

    plugin.postCreate = function(data, callback){ // Edit data here callback(null, data); }

    You can access all Data you can work with via the data object.

    All those filter-hooks needs callbacks. The callback contains the modified / added / removed data.

    Whats inside the data object?

    The data object contains two main objects.

    this.post this.data post: { pid: 259, uid: 2, tid: 111, content: '### This is just a little snippet.', timestamp: 1617150411838 }, data: { uuid: '7277s31-6d23-43sa-1284-ad27e42yx879', title: 'How to add custom data to post serverside - in a nutshell', content: '### This is just a little snippet.', thumb: '', cid: '2', tags: [], uid: 2, req: { [...] }, timestamp: 1617150411838, fromQueue: false, tid: 111, ip: '111.123.2123.21', isMain: true } }

    With all the data you can work with. But only this.post is directly effected (lol) to the post Object.
    If you add data here. It will be attached to the post forever and you can access it any time. Even after plugin disable.

    So now add custom data:

    plugin.postCreate = function(data, callback){ // adds data **PERMANENT** to post // before any other procession -> RAW DATA (markdown) //data.post.myData = "directly effected to post you can work with it in next step"; //data.data.myData = "other data for other things I don't know"; var myData = {}; myData.name = "Schmock"; myData.signature = "raz0rn"; // Stick myData to post object data.post.myData = myData; // Debug? // console.log("POST CREATE", data); // finish the process() - passes on modified data callback(null, data); }

    So myData has added to post:

    post: { pid: 259, uid: 2, tid: 111, content: '### This is just a little snippet.', timestamp: 1617150411838, myData: { name = "Schmock", signature = "raz0rn", } }

    The data is stored. Everybody is happy.

    dance minions

    How to add dynamic data before render a post in template It wont be saved to the object. You can use this for dynamic things or logic before rendering the page.:

    You need the following hook:

    { "hook": "filter:topics.addPostData", "method": "addPostData" }

    This hook is fired before engine renders the template.
    It also needs a callback because its a filter-hook.

    plugin.addPostData = function(data, callback){ // modify data temporarily before it gets passed on to next step callback(null, data); }

    Same thing as above. Only the hook is different. And the data we are changing is temporarily.
    Data contains all data we can use for the dynamicness lol: .

    plugin.addPostData = function(data, callback){ // You can work with pre-parsed and already saved data .... // or put in something very flexible without saving to db like jquery-like dynamic etc etc // Debug? // console.log("addPostData?", data) var _posts = data.posts; _posts.forEach(function(post){ if(post.myData){ // add data to post if "myData" is there post.content = "THIS POST HAS MY OWN DATA -> CONTENT IS OVERWRITTEN"; } // this here affects all posts post.user.signature = "Ihr seid alle Schmocks!"; }); // Overwrite data and pass modified data on to the template engine data.posts = _posts; callback(null, data); }

    Now you can work with posts like a boss.

    Bildschirmfoto 2021-03-31 um 03.10.32.png

    dab

    Thanks and bye

    Important Note:

    Remind, that myData is available via API.

    https://nodebb.development.fail/api/topic/114/new-post

    returns your added data

    "content": "THIS POST AS MY OWN DATA -> CONTENT IS OVERWRITTEN", "myData": { "name": "Schmock", "signature": "raz0rn" }
  • 0 Votes
    18 Posts
    2k Views
    barisB

    Yes you can use them inside the AMD module but keep in mind once you add an event listener on the window object it will be called everytime there is an action:ajaxify.end. If you don't want it triggered after you leave that page you need to turn it off with $(window).off('eventName', myMethod)

  • 0 Votes
    5 Posts
    926 Views
    dogsD

    @pitaj Nice that was easy! Thank you 🙂

  • 0 Votes
    5 Posts
    738 Views
    E

    @dogs Thanks.
    Can you point me to some materials explaining how the frontend and hooks interact?
    I don't complete follows their discussion on data.submittedData and is still confused about which variable is the post data stored in and which hooks are involved when it is passed around.

    Edit:
    Also found this, maybe relevant
    Difference between templateValues and templateData

  • 0 Votes
    5 Posts
    895 Views
    dogsD

    @baris Thank you very much. This worked! 🙂

    €: I additionally use the hook

    $(window).on('action:ajaxify.start', function (ev, data) { $('div.topic-header-image').hide(); });

    so that the header container with the image is hiding immediatly and before ajaxify.end 👍

  • This topic is deleted!

    2
    0 Votes
    2 Posts
    15 Views
  • 0 Votes
    5 Posts
    655 Views
    magnusvhendinM

    Yep, I see the issue. I'm not looking to push any changes. It was more out of curiosity on why there are several different names within essentially the same function.

  • Accesing JQuery in widget template

    Unsolved
    2
    0 Votes
    2 Posts
    365 Views
    barisB

    Javascript embedded in the widget can't access the jquery object on page load since jquery hasn't loaded yet. You can use something like this

    (function() { function onLoad() { // widget code } if (window.jQuery) { onLoad(); } else { window.addEventListener('DOMContentLoaded', onLoad); } })();