• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

How send var from method to method

Scheduled Pinned Locked Moved NodeBB Plugins
4 Posts 2 Posters 1.3k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sergej-saveljevS Offline
    sergej-saveljevS Offline
    Cергей Савельев Plugin & Theme Dev
    wrote on last edited by sergej-saveljev
    #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.

    1 Reply Last reply
    0
  • sergej-saveljevS Offline
    sergej-saveljevS Offline
    Cергей Савельев Plugin & Theme Dev
    wrote on last edited by
    #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.

    1 Reply Last reply
    0
  • sergej-saveljevS Offline
    sergej-saveljevS Offline
    Cергей Савельев Plugin & Theme Dev
    wrote on last edited by
    #3

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

    1 Reply Last reply
    0
  • B Offline
    B Offline
    Alexander Bogdanov GNU/Linux
    wrote on last edited by
    #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.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development