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.

How to add a navbar above navbar?

Hey guys,

so i'm trying to write (emphasis on trying) a custom plugin that will add a navbar above current navbar.
And honestly i'm lost.. my PHP skills are none but i do have some knowledge of programming.

I'd appreciate a lot every hint/direction of where to start.
I think i figured out that i have to use function Base_render_before and $Sender->smth->AddString('some html here')
where smth is something that i have no idea what.. a hook that i should use?

Anyway..help appreciated :)

I'm using Vanilla 2.1 and Vanilla bootstrap theme (united).

Best Answers

Answers

  • edited June 2014

    hgtonight hi and thanks!
    Yeah thats my backup plan (default.master.tpl) but not a very good one for me because my intention is to pull page titles and links from a database..
    And smartys php tag is deprecated now so.. any other ideas?

    Thanks!

  • hgtonighthgtonight MVP
    edited June 2014

    EDIT - Please read the follow up to this post for corrected code.

    For dynamic content, I suggest you add a new asset, create a module that contains your logic, and then add this module to every page.

    1. Create a new asset in your /themes/bootstrap/views/default.master.tpl file using the smarty tag {asset name="AboveNavbar"}.
    2. Create a file in /themes/bootstrap/modules called class.dynamicnavbarmodule.php and paste in the following code:

      <?php if(!defined('APPLICATION')) exit();
      /**
       * Renders a dynamic navbar
       */
      class DynamicNavbarModule extends Gdn_Module {
      
        public function __construct($Sender = '') {
          parent::__construct($Sender);
          $this->Data('Menu', 'this is my sweet new navbar!');
        }
      
        public function AssetTarget() {
          return 'AboveNavbar';
        }
      
        public function ToString() {
          $Menu = $this->Data('Menu');
          if($Menu) {
            return $Menu;
          }
        }
      
      }
      
    3. Add the module to every page with the following code in your /themes/bootstrap/class.bootstrapthemehooks.php file:

      class BootstrapThemeHooks implements Gdn_IPlugin {
        /** No setup required. */
        public function Setup() { }
      
        public function Base_Render_Before($Sender) {
          $Sender->AddModule('DynamicNavbar');
        }
      }
      

    If all went well, you should see your 'this is my sweet new navbar!' text above your navbar.

    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.

  • Well i tried your code and its not working for me.. page loads fine but no 'sweet new navbar' message is shown

  • @hgtonight said:
    Let me know if you find any other issues with this example code.

    This one works like a charm! Thanks a lot!

Sign In or Register to comment.