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.
Options

How would I do this?

adrian.adrian.
edited August 2005 in Vanilla 1.0 Help
I need to add an extra menu into the top of each page. I need to basically just insert a list into the header area, just before the main menu at the moment. How would I go about doing this?

Comments

  • Options
    find the 'add user tab' extension in the documentation, that will allow you to do pretty much this with a little fiddling.
  • Options
    I think he's wanting to add an entirely new menu. I need the same thing on a site I'm developing, and so will tackle it when that moves ahead, but that may not be for a month or so, so won't be much use if in a hurry ._. In case anyone is confused as to the purpose and distinction, entirely new menu is for *site wide* navigation, whereas adding tabs to the current menu is only really appropriate for forum specific things.
  • Options
    MarkMark Vanilla Staff
    Oh, so you want a menu sitting above vanilla? YOu need to create your own control and add it to the page obect to fire in the menu_render event.
  • Options
    yeah, thats the one. and how would I create my own control?
  • Options
    edited August 2005
    like this:
    
    
    /*
    Extension Name: Change the header
    Extension Url: http://lussumo.com/docs/
    Description: Allows you to manually edit the header of Vanilla forums
    Version: 1.0
    Author: Martin Sweeney
    Author Url: http://martini.me.uk/
    */
    
    class ManualHead  {
            var $Context;
    
            function ManualHead (&$Context) {
                    $this->Context = &$Context;
            }
    
            function Render() {
                    $this->Context->Writer->Write("-----CHANGE THIS TO YOUR MENU ETC----------");
            }
    
    }
    
    $ManualHead = $Context->ObjectFactory->NewContextObject($Context, "ManualHead");
    $Page->AddControl("Menu_Render", $ManualHead);
    
    ?>
    
    where you replace the -----CHANGE THIS TO YOUR MENU ETC---------- bit with your menu or whatever.

    and if you need to add extra tags at the foot to close off the markup you added after the body tag, do this:
    
    class ManPageEnd {
    
            var $Context;
    
            function ManPageEnd (&$Context) {
                    $this->Context = &$Context;
            }
    
            function Render() {
                    $this->Context->Writer->Write("---YOUR EXTRA CLOSING TAGS HERE---");
            }
    }
    
    $ManPageEnd = $Context->ObjectFactory->NewContextObject($Context, "ManPageEnd");
    $Page->AddControl("Page_Unload", $ManPageEnd);
    
    Save the code as a .php file in your extensions directory, and enable through the admin extensions management.

    HTH

    M.
  • Options
    You absolutely rule. Wholeheartedly. Cheers mate.
  • Options
    Is there a way to add an external php file (say, /includes/header.php) to this area, or will I get a never ending series of parse errors? ----CHANGE THIS TO YOUR MENU ETC----
  • Options
    MarkMark Vanilla Staff
    Hmm. I'm not sure. But I can think of one way to find out.... :)
  • Options
    Well, it works, but not exactly like I want it to work. As it stands, it's putting the file (or text) into the area before the doctype statement in the html. Is there a way to specify where on the page I could get this to parse, rather than at the very beginning?
  • Options
    MarkMark Vanilla Staff
    Oh, try the next event in the Page object's event chain. The full list of page object events are: 1. Page_Init 2. Head_Render 3. Menu_Render 4. Panel_Render 5. Body_Render 6. Foot_Render 7. Page_Unload
  • Options
    edited August 2005
    JP - is it a file that needs to be parsed, or is it just flat html/text file?


    M. function Render() { $header = implode('', file('/path/to/your/include/directory/includes/header.php')); $this->Context->Writer->Write($header); } </pre>
  • Options
    MarkMark Vanilla Staff
    nice one, sweeney :)
  • Options
    I'll test it out tonight and see how it works.

    I'm passing different files in different areas. One type of file needs
    to be parsed and the other is just a flat html file (global header info).
    After playing around with it a bit last night (unfortunately, I'm no php
    coder) I got it to do somewhat what I wanted, but I'll still need to work
    on it a bit more.

    Mark - are the page object events called like this, or am i totally off?

    function HeadRender() {
    function FootRender() {
  • Options
    thats to create the function not use it. Useing it is normally just HeadRender(whatever information needs passing here) but i'm not certain about that with OOP.
  • Options
    MarkMark Vanilla Staff
    You add your controls to the page object like this:

    $Page->AddControl("Page_Unload", $PageEnd);

    That code would add a control called "$PageEnd" to the "Page_Unload" event.

    I've started the document on how to create and add controls to the page object, but it is not yet finished. You can check it out here:

    http://lussumo.com/docs/doku.php?id=vanilla:development:customcontrols
This discussion has been closed.