Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Force module on all pages

I embarrassed to have to ask this as I sure it must be simple and I have tried a number of things from these discussions that I thought might be relevant without luck, so....how do I force a specific module to show in the panel on all pages? For example I am considering having the Categories module (the one that list all of the available categories along with the number of discussions in each) in the sidebar of every page, even the categories page, message page etc. How can I force this to happen?

I am running 2.1.1

Thanks

Alan

Comments

  • Options
    hgtonighthgtonight ∞ · New Moderator
    public function Base_Render_Before($Sender) {
      $Sender->AddModule('CategoriesModule');
    }
    

    Add that to a plugin.

    Or add this to your master template {module name="CategoriesModule"}.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    Thanks hgtonight. Is there something I can add to either of the above so I can insert it between existing modules that the panel renders?

  • Options
    peregrineperegrine MVP
    edited September 2014

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Oh that's really cool. I'd come across the module array options in the config file but didn't realize it would apply to extra bits I added via the render event. Sweet.

  • Options

    I guess the missing piece here is how do I stop two copies of the module appearing on pages that already have it? My testing seems to indicate that the routine above will add the Categories module to every page, even those where it already exists. How can I check to see if it will automatically get added to that page and not add a second copy?

  • Options
    hgtonighthgtonight ∞ · New Moderator

    The plugin method I posted should check to see if the module exists before adding it.

    The template way will never check and will always be displayed.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    peregrineperegrine MVP
    edited September 2014

    @hgtonight said:
    The plugin method I posted should check to see if the module exists before adding it.

    The template way will never check and will always be displayed.

    @hgtonight said:
    public function Base_Render_Before($Sender) {
    $Sender->AddModule('CategoriesModule');
    }

    Add that to a plugin.

    @alan0209‌

    or themehooks will work as well. @alan0209‌ , if you are unfamiliar with themehooks, here is an example

    http://vanillaforums.org/discussion/comment/210958#Comment_210958

    there is also one in the mobile theme as well.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Hmm I must be doing something wrong then. When testing I simply added the following to my themehooks file

    public function Base_Render_Before($Sender) {
        $Sender->AddModule('CategoriesModule');
    }
    

    That adds a the categories menu to the panel of my homepage (the categories page) as I wanted. If I click to go into a specific category though then I end up with 2 copies of the menu in the panel. If I remove the above code then I am back to no categories panel menu on the Categories page and a single copy when within a category. Any suggestions?

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    I wouldn't use Base_Render_Before, but add it to any controller "manually" by using something like CategoriesController_Render_Before. But if you want to use Base_Render_Before, you might want to check some things:

    public function base_render_before($Sender) {
        if(
            array_key_exists('Panel', $Sender->Assets) &&
            !array_key_exists('CategoriesModule', $Sender->Assets['Panel'])
        ){
            AddModule...
        }
    

    Don't know if those are arrays and the code works like that, but you get the idea...

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    edited September 2014

    Okay, quick test...

    Either this:

        public function base_render_before ($Sender) {
            if (array_key_exists('Panel', $Sender->Assets) && !array_key_exists('CategoriesModule', $Sender->Assets['Panel'])) {
                $Sender->AddModule('CategoriesModule'); 
            } 
        }
    

    or that

        public function categoriesController_render_before ($Sender) {
            $Sender->AddModule('CategoriesModule');
        }
    

    AddModule doesn't make duplicate checks

  • Options

    Ah Ok thanks for that. The top one was working (avoiding duplicates) but crashing the site when I tried to go to activities, dashboard etc (Something has gone wrong. etc). The bottom one wasn't causing crashes but was still doubling up. I've merged the two and ended up with

    public function categoriesController_render_before ($Sender) {
            if (array_key_exists('Panel', $Sender->Assets) && !array_key_exists('CategoriesModule', $Sender->Assets['Panel'])) {
                $Sender->AddModule('CategoriesModule');
            }
        }
    

    Which seems to do the job.

    Presumably there is something specific tot he Categories module that doesn't work if it is on a profile related page. I'll have a play and see if I can work out what is breaking.

    Thanks again

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @alan0209 said:

    Presumably there is something specific tot he Categories module that doesn't work if it is on a profile related page. I'll have a play and see if I can work out what is breaking.

    Thanks again

    I'd assume it is because profile is in /applications/dashboard application while the categories module is in /applications/vanilla. Try if copying /applications/vanilla/views/modules/categories.php to /applications/dashboard/views/modules/categories.php helps.

    It is not the most elegant solution, but maybe the most simple (if it is working that way)

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @R_J said:
    Okay, quick test...
    AddModule doesn't make duplicate checks

    Ah, I misread the source. :)

    I would rather modify the module class to call the view and application folder explicitly than copy views around. This way, you create a custom module and just unset all instances of the original.

    class CustomCategoriesModule extends CategoriesModule {
      public function __construct($Sender = '') {
        parent::__construct($Sender);
        $this->_ApplicationFolder = 'vanilla';
      }
    
      public function Name() {
        return 'CategoriesModule';
      }
    }
    

    Then change your plugin hook to be:

    public function Base_Render_Before($Sender) {
      unset($Sender->Assets['Panel']['CategoriesModule']);
      $Sender->AddModule('CustomCategoriesModule');
    }
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Your a developer, I'm a slaughter... :o

  • Options

    Thanks for more good tips. In the end I decided I wanted to pool the menus from DiscussionFilter and the Categories module so I made a new module with bits from both. I now have a single menu that works on all pages. Might prove unwieldy in the real world but seems to be working OK for the moment so I'll see how it goes.

Sign In or Register to comment.