How send var from method to method

NodeBB Plugins
  • Plugin & Theme Dev
    #1

    Please, tell me how send variable or array from method in to other method? For example, I create method hook filter:category.get and I want send to method hook filter:widgets.getAreas or how in my example filter:widgets.frontGetAreas. I can not find the solution.

  • Plugin & Theme Dev
    #2

    I need get category name and put to widget html. I do this as follows:
    plugin.js

    {
        "id": "nodebb-plugin-myplugin",
        "name": "Plugin name",
        "url": "Path to Github",
        "library": "./index.js",
        "staticDirs": {
            "images": "./public/images"
        },
        "scripts": [
            "./public/js"
        ],
        "less": [
            "./public/less/style.less"
        ],
        "hooks": [
            { "hook": "filter:category.get", "method": "categoryGet" },
            { "hook": "filter:widgets.frontGetAreas", "method": "widgetsGet" }
        ]
    }
    

    filter:widgets.frontGetAreas it's my fireHook.
    index.js:

    (function(module) {
    	"use strict";
    
        var cat = {},
            category = false,
    		home = false;
        
        
        cat.categoryGet = function(params, callback) {
    		
    		category = params;
            
            callback(null, params);
            
        };
        
        
        cat.widgetsGet = function(data, callback) {
    		
    		var header = JSON.parse(data[0].header),
    			headernew = [];
    		
    		header.forEach(function(item){
    			
    			if ( item.data.title == 456 ){
    				
    				item.data.html = '<h1>'+category.category.name+'</h1>';
    				item.data.html += '<p>'+category.category.description+'</p><p>&nbsp;</p>';
    				
    				headernew.push(item);
    				
    			}
    			
    	   	});
    		
    		
    		data[0].header = JSON.stringify(headernew);
    		
            
            callback(null, data);
            
        };
    
    module.exports = cat;
        
    }(module));
    

    Look at this nonsense)))

    I have an idea, I'll try to implement.

  • Plugin & Theme Dev
    #3

    My idea is not universal. I would like to know the universal solution.

  • GNU/Linux
    #4

    In order for your code to work you have to be sure that 1) categoryGet and widgetGet are always called in context of the same request and 2) none of them are called with another request in between.


Suggested Topics


  • 0 Votes
    1 Posts
    828 Views

  • 0 Votes
    3 Posts
    1625 Views

  • 0 Votes
    1 Posts
    610 Views

  • 0 Votes
    2 Posts
    1319 Views

  • 0 Votes
    8 Posts
    3021 Views

| | | |