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.

Add own Navigation Tabs

Discussion in 'Development Tutorials [Archive]' started by ragtek, Oct 6, 2010.

  1. ragtek

    ragtek Guest

    This is a VERY BASIC tuturial how to add own Tabs.
    See the quote for more infos;)
    1. Create your classfile in the xenforo directory. I named it ragtekTab
    class XenForo_ragtekTab
        * add the "info" tab to the navbar
        * @param array $extraTabs
        * @param string $selectedTabId
    public static function addNavbarTab(array &$extraTabs$selectedTabId)
    $extraTabs['info'] = array(
    'title' => new XenForo_Phrase('ragtek_infopage_navbartitle'),//phrase with the title for the link
    'href'  => XenForo_Link::buildPublicLink('info'),
    'linksTemplate' => 'ragtek_infopage_navbar',      //if you want to have a "sub menu" you can create a template for this
    'position'  =>  'middle'  //since beta 5, you can choose the position, where the link should be placed      possible positions: [SIZE=3][FONT=Arial]middle end home[/FONT][/SIZE]
    You need a class with an static method.
    The method have to parameters (as said in the documentation^^)

    2. Create a Code Event Listener which "listens" to navigation tab
    Then you have to set the class & method name
    Execute Callback: xenforo_ragtekTab :: addNavbarTab

    That's it.
    Now there should be a new tab;)

    A quick note:

    If you use a phrase for the tab title, you SHOULD cache the phrase.
    This will save you an global DB Query!
    Pr0totype2, DBA, Fuhrmann and 25 others like this.
  2. RickM

    RickM Well-Known Member

    Nice work :)
  3. Lynne

    Lynne Member

    Nice introductory. Thanks!
  4. Lawrence

    Lawrence Well-Known Member

    Just to add, if you are going to have an addon that is permission based, or you will turn off, you need to check for permissions / on/off state here as well so that the tab will reflect the state. ie:

                $options = XenForo_Application::get('options');
                if ($options->myaddonisTurnedOn)
                          $extraTabs['my_tab'] = array(
                          'title' => $options->mytabName,
                          'selected' => ($selectedTabId == 'mytabName'),
                          'href' => XenForo_Link::buildPublicLink('myaddonLocation'),
                          'linksTemplate' => 'myAddon_links',
                          'linksTitle' => $myLinks
    Perspektif, Rob Fritz and feldon30 like this.
  5. ragtek

    ragtek Guest

    We have realy to check if a add-in is active`?
    That's not very nice and IMHO a huge design mistake.
    Why is xenforo executing code from inactive add-ons? (can't belive it's happening^^)
  6. Lawrence

    Lawrence Well-Known Member

    XenForo does not do that. If the Add-on is inactive it is inactive.

    My example is referring to if Admins have an Option to allow a specific group to access a new page, then only that group should see the tab (seems sensible to me). Or if the addon has an option to be turned on or off, the tab should be viewable or not, depending on the option. The example above demonstrates how to do that.

    I changed the example to reflect turned on.
  7. ragtek

    ragtek Guest

    quote="Lawrence, post: 84258"]XenForo does not do that. If the Add-on is inactive it is inactive.
    ok,i've misunderstood it^^
  8. Jaxel

    Jaxel Well-Known Member

    How do I add and remove tabs from the SECONDARY tablinks (not navtab) based on permissions?

    I have the following navigation class:
    class EWRporta_Listeners_Navigation
    	public static function navtabs(array &$extraTabs, $selectedTabId)
    		$extraTabs['portal'] = array(
    			'title' => 'Portal',
    			'href' => XenForo_Link::buildPublicLink('full:portal'),
    			'selected' => ($selectedTabId == 'portal'),
    			'linksTemplate' => 'EWRporta_Navtabs',
    The template 'EWRporta_Navtabs' controls the secondary tablinks.
    <ul class="secondaryContent blockLinksList">
    	<li><a href="{xen:link portal}">Portal</a></li>
    I want to be able to add tablinks based on permissions assuming I have the following permissions class:
    class EWRporta_Model_Perms extends XenForo_Model
    	public function canCreate(array $viewingUser = null)
    		if (XenForo_Permission::hasPermission($viewingUser['permissions'], 'EWRporta', 'canCreate'))
    			return true;
    		return false;
    CyberAP likes this.
  9. Lawrence

    Lawrence Well-Known Member

    Do the check in the nav listener, and extend the array with something like: 'links', and populate it with an array of links. This is what I did for my XenStaff Add-on.

  10. Laric

    Laric Active Member

    Can you self control in what order the links are added in the navbar? (I haven't had a chance to take a look at it yet)
    Like for instance I would like to place my portal navbar link first in the order.
  11. José Guedes

    José Guedes Active Member

    I think I found a better way to do this, if you just want to reefer a link to somewhere.

    In the navigation template just add before the part that says "<!-- no selection -->" if you want to be the last link, else just do it before the one that you want.
    In this example, I used my clan's radio link.

    <!-- radio -->
    		<li class="navTab radio PopupClosed"><a href="http://radio.superialbuilders.com" class="navLink">Radio</a></li>
    You can see two examples in my clan forums:
    semprot, atmaca, snowman and 3 others like this.
  12. Martyn

    Martyn Active Member

    edit never mind i read wrong! lol
  13. ragtek

    ragtek Guest

    Do you know how to set the the activ tab in the secondary navbar?
  14. MordyT

    MordyT Active Member

    I would like to see a mod like sstabs (vb4) for xenforo... That would be ultimate...
    Brett Peters, Veer and hcmagix like this.
  15. ragtek

    ragtek Guest

    I've updated the article:)
  16. Jaxel

    Jaxel Well-Known Member

    Just so you know... the 'selected' key is no longer required.
  17. Digital Doctor

    Digital Doctor Well-Known Member

    Great article.
    I think this would get plenty of installs if it were an Addon that was uploadable.
    Would it be hard to make this an "uploadable" addon ?
  18. ragtek

    ragtek Guest

    No, IMHO it wouldn't be hard, BUT i don't want to code a "ugly" one, which is add-ing them on runtime.

    I have some other ideas for my cms...
  19. Digital Doctor

    Digital Doctor Well-Known Member

    Is this easier now with beta6 being released ?
  20. ragtek

    ragtek Guest


Share This Page