Resource icon

Overriding the active navigation tab

Chris D

XenForo developer
Staff member
Chris Deeming submitted a new resource:

Overriding the active navigation tab - Adding more navigational context

This very simple developer guide contains two very simple examples of where it might be a good idea to override the default navigation tab for a controller/route.

It's pretty much a single line of code you can use to set the current navigation tab to something entirely different. So why?

With XenForo 1.2 and even in earlier versions of XenForo there are times where our new add-ons/applications are extending default Controllers with new actions to display content specific to our add-ons.

One...

Read more about this resource...
 
The exact code will vary depending on the objects and properties available to the class you're working with. I'm not totally familiar with the Kotomi page, but if it doesn't somehow have access to a controller object or RouteMatch object then setting the sections won't be possible.

If you can share the current code you have, I might be able to make suggestions, but it might just not be possible.
 
I have library/LandNetwork/Tabs/Tabs.php:
PHP:
<?php
class LandNetwork_Tabs_Tabs
{
    public static function addNavbarTab(array &$extraTabs, $selectedTabId)
    {
        $extraTabs['gametypes'] = array(
            'title' => 'Gametypes',
            'href'  => 'gametypes',
            'position'  =>  'middle',
        );
        $extraTabs['players'] = array(
            'title' => 'Players',
            'href'  => 'players',
            'position'  =>  'middle',
        );
        $extraTabs['shop'] = array(
            'title' => 'Shop',
            'href'  => 'shop',
            'position'  =>  'middle',
        );
        $extraTabs['radio'] = array(
            'title' => 'Radio',
            'href'  => 'radio',
            'position'  =>  'middle',
        );

}
which is hooked into an addon titled "LandNetwork", which has a code event listener and runs the above function (addNavbarTab).

This creates the tabs fine, but do you know how I'd make the tabs selected?

The pages it links to are Kotomi Bridge pages, each coded like this:
PHP:
<?php
$startTime = microtime(true);
$kotomi_indexFile = "";
$kotomi_container = true;
$fileDir = dirname(__FILE__)."{$kotomi_indexFile}";
require "{$fileDir}/library/Dark/Kotomi/KotomiHeader.php";
require_once("library/LandNetwork/Framework/database.php");
?>

// Any HTML code, and page content.

<?php
require "{$fileDir}/library/Dark/Kotomi/KotomiFooter.php";
?>

Any help appreciated... :(
 
I'm not entirely convinced it's possible, to be honest.

I had a quick look, but it seems as though the initialisation of the XF framework is done inside the KotomiHeader and a custom front controller object.

You may want to look at using the Page Node system with callbacks or creating these as proper XF add-ons which would include a few extra steps.
 
Top Bottom