How send var from method to method
-
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 hookfilter:widgets.getAreas
or how in my examplefilter:widgets.frontGetAreas
. I can not find the solution. -
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> </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.
-
My idea is not universal. I would like to know the universal solution.
-
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.
Copyright © 2024 NodeBB | Contributors