How to not display a module

Hey,

I do not want to show DiscussionFilterModule in the index page. What's the best and safest way to achieve this?

Thanks :D

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    If you simply do not want to show it, and ask for the simplest solution, using CSS and display:none would be the answer.

    The module will nevertheless be built and the html will be transferred to the client. So if you are searching for a way to avoid that, you need some PHP code => a themehooksfile or a plugin

    The DiscussionFilterModule is a Module in the Panel which is an Asset (just like the Head, the Content and the Foot). Vanillas Gdn_Controller class has a property "Assets" which is an array with the four assets mentioned above. Each module that is added to an asset wiv the addModule() method is just another key in that array. So the trick is to unset Gdn::controller()->Assets['Panel']['DiscussionFilterModule']. You can basically do that at any time after the module has been added (which is done in the constructor of the Gdn_Controller).

    Before each of the assets is rendered, an event is thrown (in Gdn_Controller->renderAsset()). That's where I would do it.

        public function base_beforeRenderAsset_handler($sender, $args) {
           // That check is not needed, I guess. But anyway...
           /*
           if (!array_key_exists(
               'DiscussionFilterModule',
               $sender->Assets[$args['AssetName']]
           )) {
               return;
           }
           */
           unset($sender->Assets[$args['AssetName']]['DiscussionFilterModule']);
       }
    
    


    On the other hand, that event is fired 4 times (for each asset). Maybe it would be more efficient to put that one line into base_render_before

    public function base_render_before($sender) {
        unset($sender->Assets['Panel']['DiscussionFilterModule']);
    }
    

    If it should only be excluded from the Discussions page, make it discussionsController_render_before


    nithish
  • Thank you very much for the detailed explanation!!

Sign In or Register to comment.