Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

how to add custom build menu to the sidebar

This discussion is related to the Simple Pages addon.

I am experimenting with the SimplePages addon Linc made.

What i want to achieve is a custom build menu to the sidebar. I did read that i had to make a module for it.

This is what i have added to the class.simplepages.plugin.php

// No Panel, and allow more styling via body class 'SimplePage'
        include_once(PATH_PLUGINS.DS.'SimplePages'.DS.'class.simplepagesmodule.php'); // path to module
        $Sender->AddModule('SimplePagesModule', 'Panel'); // add the module
        $sender->AddCssFile('plugins/SimplePages/design/simplepages.css'); // add specific css file
        $sender->CssClass .= ' NoPanel SimplePage';
        unset($sender->Assets['Panel']);

What is the code i have to make in class.simplepagesmodule.php?

Or is there another easy way to add the menu to the sidebar?

Look here what i mean: http://forum.webprofis.nl/tuts-en-scripts#one3

Comments

  • peregrineperegrine MVP
    edited January 2015

    an example.

    • 1 remove the NoPanel from the CssClass

      $sender->CssClass .= ' NoPanel SimplePage';

    becomes
    $sender->CssClass .= ' SimplePage';

    • 2 comment out the line that unsets the Asset Panel

    // unset($sender->Assets['Panel']);

    • 3 render before discussion , unset specific modules and add your own.

       public function DiscussionController_BeforeDiscussionRender_Handler($sender) {
           unset($sender->Assets['Panel']['CategoriesModule']);
           unset($sender->Assets['Panel']['DiscussionFilterModule']);
           $SimplePagesMenuModule = new SimplePagesMenuModule();
           $sender->AddModule($SimplePagesMenuModule); 
      }
      

    -4 create SimplePages/class.simplepagesmenumodule.php

    <?php if (!defined('APPLICATION')) exit();
    
    class SimplePagesMenuModule extends Gdn_Module {
    
    
    
    
       public function AssetTarget() {
          return 'Panel';
       }
    
       public function ToString() {  
    
          echo '<div class="Box SimplePagesMenuBox">'; 
          echo Wrap(T('Jack Be Nimble'), 'h4');
          echo '<ul class="PanelInfo">';
          echo  Wrap(T("Jack be nimble"), 'li');
          echo Wrap(T("Jack be quick,"), 'li');
          echo Wrap(T("Jack jump over"), 'li');
          echo Wrap(T("The candlestick"), 'li');
          echo  "</ul>";
          echo "</div>";  
       }
    }
    

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

    mcu_hqjackmaessen
  • peregrineperegrine MVP
    edited January 2015

    which leads to a question (which hgtonight explained once that you don't need to use include for the module).

    which works if the module is in

    SimplePages/class.simplepagesmenumodule.php

    but doesn't seem to work if

    SimplePages/modules/class.simplepagesmenumodule.php

    @Linc‌ or anyone else with the savoir-faire

    how come the autoloader doesn't search the modules folder for module

    or am I confused?

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

  • hgtonighthgtonight ∞ · New Moderator

    @peregrine said:

    how come the autoloader doesn't search the modules folder for module

    or am I confused?

    It should IIRC. Make sure you clear your plugin cache maps of you move things around to force the map be rebuilt.

    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.

    peregrine
  • LincLinc Director of Development Detroit Vanilla Staff

    I seem to recall running into this recently, where the modules folder autoloads for applications but not plugins. Plugins got the shaft on several things like this that we've slowly been fixing, like the controllers limitation we removed. I'd accept a pull request that resolved it well.

    Eventually we'd like to phase out applications and make plugins first-class citizens with all of their powers.

    peregrineBleistivt
  • peregrineperegrine MVP
    edited January 2015

    @hgtonight said:
    It should IIRC. Make sure you clear your plugin cache maps of you move things around to force the map be rebuilt.

    Bingo for hgtonight!

    I disabled the plugin, moved the module in to modules folder. enabled the plugin and it worked.

    This has been the bane for me, not realizing that I have to disable plugin when messing with modules and moving around. I've spent hours in the past messing with this, sometimes things worked and sometimes they didn't for no apparent reason. The rule I tell other people "Disable your plugin when making changes and enable, I had not learned myself :). In the past I only disabled and enabled when messing with structure, permissions, and routing. Now I add a fourth messing with modules.

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

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    I'm using a simple plugin for quite some time now, which I always "use" if I sense some behavior as kind of strange:

    <?php defined('APPLICATION') or die();
    
    $PluginInfo['ClearPluginCache'] = array(
        'Name' => 'Clear Plugin Cache',
        'Description' => 'Clears plugin cache on every enable/disable of this plugin.',
        'Version' => '0.1',
        'Author' => 'Robin',
        'License' => 'MIT'
    );
    
    class ClearPluginCachePlugin extends Gdn_Plugin {
        public function setup() {
            Gdn::PluginManager()->ClearPluginCache();
        }
        public function OnDisable() {
            Gdn::PluginManager()->ClearPluginCache();
        }
    }
    
    jackmaessenperegrineBleistivt
  • @peregrine This works great! Thanks again for help ;)
    There was one thing i had to solve: this menu appears on every page in the sidebar.
    Actually i would like it only being displayed on the pages made with simplepages plugin.
    So i added in my general style.css:

    #wrapper {
    display: none;
    }
    

    And i put in a simplepages.css:

        /* fix for bootstrap theme; delete avatar area left*/
    .MessageList .Item {
     margin-left: 0px !important;
    }
    /* disable signature on simplepages */
    .UserSignature {
        display: none !important;
    }
    
    /* disable latestpostlist in sidebar */
    #LatestPostList {
        display: none;
    }
    
    /* force to display wrapper in sidebar */
    #wrapper {
        display: block !important;
    }
    

    Now the wrapper appears only on the pages made with simplepages plugin :D

  • @R_J said:
    I'm using a simple plugin for quite some time now, which I always "use" if I sense some behavior as kind of strange:

    simple and nice! good idea.

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

  • @jackmaessen said:
    peregrine This works great! Thanks again for help ;)
    There was one thing i had to solve: this menu appears on every page in the sidebar.

    I overlooked that.

    if you want that routine only on simple pages. a simper way to do it

     public function DiscussionController_BeforeDiscussionRender_Handler($sender) {
         //add this
           if (!val('Type', $sender->Data('Discussion')) == 'SimplePage') {
                return;
            }
    

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

    jackmaessen
  • jackmaessenjackmaessen ✭✭✭
    edited January 2015

    @peregrine that's more efficient; i agree! thanks again

  • hgtonighthgtonight ∞ · New Moderator

    @peregrine said:
    if (!val('Type', $sender->Data('Discussion')) == 'SimplePage') {
    return;
    }

    This is bad form as you are relying on PHP's truthiness of strings to evaluate the return.

    You should use something like:

    if(strtolower(val('Type', $sender->Data('Discussion'))) !== 'simplepage') {
      return;
    }
    

    This forces it to only keep going when the type is simplepage since strtolower() returns a string and !== forces type checking.

    If you don't do something like this, the function will still be executed on discussions that have any "truthy" string set as the type. E.g. pretty much anything.

    More on PHP truthyness here: http://php.net/manual/en/types.comparisons.php

    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.

    peregrinejackmaessen
  • peregrineperegrine MVP
    edited January 2015

    good idea. might want to modify the existing plugin code line 77 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.

Sign In or Register to comment.