Skip to content
  • Home
  • Categories
  • Recent
  • Popular
  • World
  • 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
Brand Logo
v3.12.1 Latest
Buy Hosting
  1. Home
  2. NodeBB Plugins
  3. How to distinguish the home page of the category page?

How to distinguish the home page of the category page?

Scheduled Pinned Locked Moved NodeBB Plugins
17 Posts 2 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Cергей Савельев Plugin & Theme Dev
    wrote on last edited by sergej-saveljev
    #2
    var post = false,
        category = false,
        home = false;
    
    mod.categoriesBuild = function(params, callback) {
        home = true;
        callback(null, params);
    };
    
    mod.categoryGet = function(params, callback) {
        category = true;
        callback(null, params);
    };
    
    mod.postParse = function(params, callback) {
        post = true;
        callback(null, params);
    };
    
    mod.widgetsGet = function(data, callback) {
        if ( category ){
            ...
        }
        else if ( post ){
            ...
        }
        else if ( home ){
            ...
        }
        post = false,
            category = false,
            home = false;
        callback(null, data);
    };
    

    This is my bad variant.

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

      @sergej-saveljev said:

      widgetsGet

      It is my fireHook for get widgets in frontend.

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

        How get app in any plugin methods?

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

          Probably, it is possible to determine the pathname received app and use it to identify a resource open the client.

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

            My goal is that want to display html with h1 and description blocks for pages categories, subcategories and the post pages on the basis of their field name and description.

            I chose to use widgets. Maybe there is a right decision?

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

              Thank you all for your attention !!! 🙂 Problem was solved !!! 😄

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

                GitHub Pull Request 😉

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Cергей Савельев Plugin & Theme Dev
                  wrote on last edited by
                  #9
                  mod.widgetsGet = function(data, callback) {
                  	template = data.templates[1].replace('.tpl', '');
                  	if ( template == 'categories' ){
                          console.log('Home page opened');
                      }
                      else if ( template == 'category' ){
                  		console.log('Subcategory page opened');
                      }
                      else if ( template == 'topic' ){
                  		console.log('Topic page opened');
                      }
                      callback(null, data.data);
                  };
                  
                  1 Reply Last reply
                  0
                  • yariplusY Offline
                    yariplusY Offline
                    yariplus Community Rep
                    wrote on last edited by
                    #10

                    If I understand you correctly, It sounds like you should be adding this to your widget or theme.

                    I don't think adding a filter is what you want to do. Filters are used to modify data, an "action" would be better if you're trying to figure out when a specific widget area is requested. But, this would not be useful in this regard because it's also called on the ACP Widget page.

                    What you probably want to do is use the existing "filter:widget.render:widgetname" hook,

                    plugins.fireHook('filter:widget.render:' + widget.widget, {
                    	uid: uid,
                    	area: area,
                    	data: widget.data
                    }
                    

                    The area that is passed has area.template already.

                    S 1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Cергей Савельев Plugin & Theme Dev
                      replied to yariplus on last edited by
                      #11

                      @yariplus I can not understand why in the data that is returned fireHook only widget.data?

                      yariplusY 1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Cергей Савельев Plugin & Theme Dev
                        wrote on last edited by
                        #12

                        In the code src/widgets.js file seems to be all right.

                        1 Reply Last reply
                        0
                        • yariplusY Offline
                          yariplusY Offline
                          yariplus Community Rep
                          replied to Cергей Савельев on last edited by
                          #13

                          @sergej-saveljev That's okay, it is a little confusing. The hook returns uid, area, and data. For example, the function you would assign to "filter:widget.render:widgetname" would be like:

                          mod.renderWidget = function(data, callback) {
                             console.log(data.area.template); // This is the template you are looking for.
                             console.log(data.data); // This is the Widget's setting data.
                             console.log(data.uid); // This is the User who is viewing the page.
                             return callback();
                          }
                          
                          S 1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            Cергей Савельев Plugin & Theme Dev
                            replied to yariplus on last edited by
                            #14

                            @yariplus returned undefined for all console.log calls

                            1 Reply Last reply
                            0
                            • yariplusY Offline
                              yariplusY Offline
                              yariplus Community Rep
                              wrote on last edited by
                              #15

                              Did you create the widget? It won't work if there's no widget to render.

                              Do you have a link to your full code?

                              S 1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                Cергей Савельев Plugin & Theme Dev
                                replied to yariplus on last edited by
                                #16

                                @yariplus said:

                                Did you create the widget? It won't work if there's no widget to render.

                                Do you have a link to your full code?

                                Yes, I created widget. I deleted code, but he was about, how you wrote.

                                1 Reply Last reply
                                0
                                • yariplusY Offline
                                  yariplusY Offline
                                  yariplus Community Rep
                                  wrote on last edited by
                                  #17

                                  Hmm, I'm not sure why it wouldn't work then, that's pretty much exactly my code.

                                  1 Reply Last reply
                                  0

                                  Copyright © 2024 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
                                  • World
                                  • Top
                                  • Tags
                                  • Users
                                  • Groups
                                  • Documentation
                                    • Home
                                    • Read API
                                    • Write API
                                    • Plugin Development