1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

[How-To] Create New Help Menus

Discussion in 'Development Tutorials [Archive]' started by James, May 14, 2011.

  1. James

    James Well-Known Member

    This tutorial will show you how to create a new help menu. For the purposes of this tutorial, we will create an About Us menu.

    Step 1:
    Create a folder named HelpMenu in library
    Inside HelpMenu, create 2 folders named ControllerPublic and Listener
    Inside ControllerPublic, create a file named Help.php
    Inside Listener, create a file named LoadClassController.php

    Your directory tree should be:
    -| Library
    --| HelpMenu
    ---| ControllerPublic
    ----| Help.php
    ---| Listener
    ----| LoadClassController.php

    Inside the file named Help.php, we need to create a function to resolve the new About Us help item, which will be this code:
    Code:
    
    <?php
    
    class HelpMenu_ControllerPublic_Help extends XFCP_HelpMenu_ControllerPublic_Help
    {
    public function actionAbout()
    {
    return $this->_getWrapper('about',
    $this->responseView('XenForo_ViewPublic_Help_About', 'help_about')
    );
    }
    }
    
    
    Save and close that file.

    Open up LoadClassController.php inside Listener and add the following code:
    Code:
    
    <?php
    
    class HelpMenu_Listener_LoadClassController
    {
        public static function extendHelpController($class, array &$extend)
        {
            if ($class == 'XenForo_ControllerPublic_Help')
            {
                $extend[] = 'HelpMenu_ControllerPublic_Help';
            }
        }
    }
    
    
    Save that file.

    Now, ensuring debug mode is enabled, navigate to admin.php?code-event-listeners/add and input the following information:
    Listen to Event: load_class_controller
    Execute Callback: HelpMenu_Listener_LoadClassController :: extendHelpController

    Add your description and callback execution order as appropriate.

    Now, once you've saved that, create a new template named help_about, populate it with your information and you can find it readily available at XFroot/help/about.

    Now you need to edit the templates to add the links.
    Navigate to help_wrapper
    Find:
    Code:
    <li><a href="{xen:link help/trophies}" class="{xen:if "{$selected} == 'trophies'", 'secondaryContent', 'primaryContent'}">{xen:phrase trophies}</a></li>
    Add underneath:
    Code:
    <li><a href="{xen:link help/about}" class="{xen:if "{$selected} == 'about'", 'secondaryContent', 'primaryContent'}">About Us</a></li>
    
    The end result is this:
    Screenshot_1.png

    If you have any questions, please post below.

    Also, to add these links to other areas of the help menu (such as sub-navigation, drop-down), see Brogan's tutorial: Add new entries to the help page | XenForo Community
     
    EgyKit, MsJacquiiC, Mow and 11 others like this.
  2. James

    James Well-Known Member

    Q: I already have a page node with my about us information - how do I transfer it to the Help menu?
    A: Open up Help.php, find:
    Code:
    return $this->_getWrapper('about',
    $this->responseView('XenForo_ViewPublic_Help_About', 'help_about')
    Replace the help_about at the end with the name of your template (such as _page_node.nodeid). Example:
    Code:
    return $this->_getWrapper('about',
    $this->responseView('XenForo_ViewPublic_Help_About', '_page_node.3')
    Q: I want to change the URL from /help/about to /help/about-us - how do I do it?
    A: Open up Help.php, find:
    Code:
    public function actionAbout()
    Change to:
    Code:
    public function actionAboutUs()
    You will then need to re-edit the help_wrapper template and update the {xen:link help/about} to {xen:link help/about-us}.
     
    Veer, Fuhrmann, DarkSign and 2 others like this.
  3. Nasr

    Nasr Well-Known Member

    What happens with upgrades? Do these need to be reapplied?
     
  4. James

    James Well-Known Member

    Only edits to the help_wrapper template will need to be reapplied, the rest of the information is stored externally as an add-on.
     
  5. Brogan

    Brogan XenForo Moderator Staff Member

    Nice work James, another thing added to my "To Do" list.
     
  6. James

    James Well-Known Member

    You can actually add page node templates instead of creating new ones, if you see the first question. You could just take your page node and use that template instead of creating the new one!
     
  7. Anthony Parsons

    Anthony Parsons Well-Known Member

    I get this error with this using 1.1 beta4 on a dev install:

    Fatal error: Class 'HelpMenu_ControllerPublic_Help' not found in /home/*******/public_html/library/XenForo/FrontController.php on line 405
     
  8. James

    James Well-Known Member

    I'll give this another shot later today. I don't see why it wouldn't work in 1.1.

    EDIT: Works fine for me in 1.1 beta 3, when I upgrade to beta 4 I'll re-test it.
     
  9. Anthony Parsons

    Anthony Parsons Well-Known Member

    This is a new install, not an upgrade, just so you're aware.
     
  10. James

    James Well-Known Member

    It says the class isn't found. Can you post the name of your classes and functions in the LoadClassController.php and the Listener.php files, and also in the code event listener?
     
  11. Anthony Parsons

    Anthony Parsons Well-Known Member

    Go figure... today it just worked. Bugs or something....

    James, how would you adjust this to add further pages to the help menu? Is it simply rename the primary directory name, create the same files over and over, change the controller to match the directory and repeat for each page?
     
  12. ChemicalKicks

    ChemicalKicks Well-Known Member

    This is right up my street, thank you for posting this up.
     
  13. James

    James Well-Known Member

    No its even easier than that. Just open helpmenu_controllerpublic_help and add actionPageName() and specify the return template. I'll post another example when I'm on the pc, I'm mobile at the minute.
     
    Anthony Parsons likes this.
  14. Anthony Parsons

    Anthony Parsons Well-Known Member

    Cheers... I'll wait until your example, so I don't screw it up... thanks for this James, this will actually really help neaten things up with FAQ's and such knowing how to create additional pages in this area...
     
  15. James

    James Well-Known Member

    Code:
     public function actionAbout()
    {
        return $this->_getWrapper('about', $this->responseView('XenForo_ViewPublic_Help_About', 'help_about')
    );
    } 
    
    change the about in actionAbout() to whatever you want your page named, such as actionMeetTheStaff (which creates help/meet-the-staff) then change the help_about to your new template for your meet the team content and change ViewPublic_Help_About to ViewPublic_Help_MeetTheTeam

    Hope this helps, took me ages on mobile. I'll create a new one tomorrow.
     
    Anthony Parsons likes this.
  16. Anthony Parsons

    Anthony Parsons Well-Known Member

    So I could stack the one file, ie:
    PHP:
    <?php
     
    class HelpMenu_ControllerPublic_Help extends XFCP_HelpMenu_ControllerPublic_Help
    {
    public function 
    actionAbout()
    {
        return 
    $this->_getWrapper('about'$this->responseView('XenForo_ViewPublic_Help_About''help_about')
    );
    }
     
    public function 
    actionRules()
    {
        return 
    $this->_getWrapper('rules'$this->responseView('XenForo_ViewPublic_Help_Rules''help_rules')
    );
    }
    }
     
  17. Anthony Parsons

    Anthony Parsons Well-Known Member

    Oh snap.... that worked.

    Got it...
     
  18. Anthony Parsons

    Anthony Parsons Well-Known Member

    Ok, next question... :eek:

    How can I get the page name to register as part of the page title? If you click on the bbcode default page, the pages title will say BBcode which will also be reflected in the browser head title.

    Pages created via this only show the forum title entered in options on every page, not an actual page title.
     
  19. James

    James Well-Known Member

    You do this in your template. For example, your template for About Us you'd put at the top of your template:
    <xen:title>About Us</xen:title>

    Look inside the help_bb_code and help_smilies etc templates to see the standard layout for help menus.
     
    Anthony Parsons likes this.
  20. wickedstangs

    wickedstangs Well-Known Member

    Where do I enable debug mode?
     

Share This Page