Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Noob needs Extension Writing Help

edited July 2006 in Vanilla 1.0 Help
Hey Guys. I really like Vanilla, and have skinned my forum for it already. However, the first time round was a hack-job, where I just edited the code directly as need be. I've decided that won't be satisfactory though, because I'd like to be able to update my forum regularly, so begun my venture in Extension Development. Apart from some basic stylesheet changes, my only real changes have been: * Adding my own header with navigation to the top of every page (other than people.php) * Removing the 'Header' div * Moving (and changing the format) of the tabs from the 'Header' div, into the 'Panel' div The first challenge I overcame relatively easily, by creating and rendering a new class extended from control. However, the second two are a little bit more intensive. That is, because now I have to move/remove/modify sections of the code. For example, taking out the 'Header' div, or changing the formatting of the tabs. I'm really stumped now, and have no idea where to go from here. I'd really appreciate it if you guys could share a little bit of your wisdom with me, because I'm sure someone knows how to do this! Thanks in advance, Luke


  • edited July 2006
    Ok, I had a look, and those tags are all immediately echoed in the menu.php theme file.

    You certainly could replace Vanilla.Control.Menu.php with your own custom control that ignores the menu.php theme file, and doesn't render the Header div. All that would be left then is to add the menu options to the panel, and style it.

    If you're planning to make even more element-rearranging changes in the future, I would consider making a custom theme instead.

    (edited for accuracy)
  • Thanks for taking the time to make an informed reply, Bergamont. Your suggestion makes sense, and to a degree that's what I have done. However won't that make updating a problem? Because I can't replace/modify the Menu class with an extension - it has to be done by manually editing the Vanilla.Control.Menu.php file as you say.
  • Actually, unless I'm mistaken, you *can* replace the Vanilla.Control.Menu class in an extension without modifying the Vanilla.Control.Menu.php file.
  • edited July 2006
    How do you do that? (specifically the render function under the Menu class)
  • edited July 2006
    This is where I tend to get a little fuzzy, so I'll leave it for someone else to fill in the fine details, but I think the basic idea is that you create a new class that inherits from Menu, overwrite the render function, create an instance of the class, and set $Menu to point to that new object.

    The problem is, I'm a little unclear as to whether, by the time your extension is loaded, it may be to late to do this.
  • edited July 2006
    Whoh, sounds complex. Anyone have any idea how to do this? (edit: I think I may have it..)
  • Thanks for your help Bergamot - It's all working now :D
  • Hey luke, care to share your solution? I'm sure others would find it useful.
  • edited July 2006
    Well, jakob_r, I wish I could format it better but here's the relevant part of default.php:

    //To Add Banner class rootnav extends Control { function rootnav(&$Context) { $this->Name = 'rootnav'; $this->Control($Context); } function Render() { $this->CallDelegate('PreRender'); echo "...banner html..."; $this->CallDelegate('PostRender'); } } if (!in_array($Context->SelfUrl, array("people.php"))) { $rootnav = $Context->ObjectFactory->CreateControl($Context, 'rootnav'); $Page->AddRenderControl($rootnav, $Configuration['CONTROL_POSITION_HEAD'] + 1); }

    //To Modify 'Menu' class if (!in_array($Context->SelfUrl, array("people.php"))) { class Menu_rev extends Menu { function Render() { ksort($this->Tabs); $this->CallDelegate('PreRender'); include(ThemeFilePath($this->Context->Configuration, '../extensions/_extensiondirectory_/menu.php')); //Revised menu.php will be called for Rendering $this->CallDelegate('PostRender'); } } $Menu_rev = $Context->ObjectFactory->CreateControl($Context, 'Menu_rev'); //create an instance of Menu_rev(ised) $Menu =& $Menu_rev; //I had to reload the Tabs, so the following code is copied from the appropriate section off 'appg/init_vanilla.php' // Cleaner suggestions welcome! // BUILD THE MAIN MENU $Menu_rev->AddTab($Context->GetDefinition('Discussions'), 'discussions', GetUrl($Configuration, './'), '', $Configuration['TAB_POSITION_DISCUSSIONS']); ... $Menu_rev->AddTab($Context->GetDefinition('Account'), 'account', GetUrl($Configuration, 'account.php'), '', $Configuration['TAB_POSITION_ACCOUNT']); } }
  • Rockin'
This discussion has been closed.