• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Adding navigation tab that stays selected.

#1
I'm trying to create a tab, for tinthe xentag but i can't keep it selected somehow. this is my code

PHP:
<?php
class Tinhte_XenTag_navtab
{
    public static function listen(array &$extraTabs, $selectedTabId)
    {
        $extraTabs['tags'] = array(
            'title' => new XenForo_Phrase('xentag_navbar_tab'),
            'href'   => XenForo_Link::buildPublicLink('full:tags'),
            'selected' => ($selectedTabId == 'tags'),
            'position'  =>  'middle'
          
        );
    }
}
whenever i click on the tags tab, the selected tab always goes to 'forums'
any help would be deeply appreciated
 

NixFifty

Well-known member
#2
I'm trying to create a tab, for tinthe xentag but i can't keep it selected somehow. this is my code

PHP:
<?php
class Tinhte_XenTag_navtab
{
    public static function listen(array &$extraTabs, $selectedTabId)
    {
        $extraTabs['tags'] = array(
            'title' => new XenForo_Phrase('xentag_navbar_tab'),
            'href'   => XenForo_Link::buildPublicLink('full:tags'),
            'selected' => ($selectedTabId == 'tags'),
            'position'  =>  'middle'
         
        );
    }
}
whenever i click on the tags tab, the selected tab always goes to 'forums'
any help would be deeply appreciated
What does your 'tags' route look like? That's where you can specify which tab will be selected.

Best example would be line 19 of /library/XenForo/Route/Prefix/Forums.php

PHP:
return $router->getRouteMatch('XenForo_ControllerPublic_Forum', $action, 'forums');
The third parameter specifies the selected tab id (in your case, it'd be 'tabs').
 
#4
Oh lol getting too complicated. well yeah i found this. got no idea how to add the route in it though.

Do you have any good php book recommendations that help me out with these things :p

in /Tinhte/XenTag/Route/Prefix/Tags.php

PHP:
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        if (in_array($routePath, self::$actions))
        {
            $action = $routePath;
        }
        else
        {
            // switched to use `resolveActionWithIntegerOrStringParam instead of the old
            // thingy `resolveActionWithStringParam` because it is more robust, specifically
            // it can handle /tags/something while the old one couldn't
            $action = $router->resolveActionWithIntegerOrStringParam($routePath, $request, 'hi', Tinhte_XenTag_Constants::URI_PARAM_TAG_TEXT);

            if (preg_match('/^page-(\d+)$/', $action, $matches))
            {
                // supports matching /tags/text/page-n links
                $request->setParam('page', $matches[1]);
                $action = 'view';
            }
        }

        return $router->getRouteMatch('Tinhte_XenTag_ControllerPublic_Tag', $action, Tinhte_XenTag_Option::get('majorSection'));
    }
 
#6
Is this the right way to do it?

PHP:
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    {
        if (in_array($routePath, self::$actions))
        {
            $action = $routePath;
        }
        else
        {
            // switched to use `resolveActionWithIntegerOrStringParam instead of the old
            // thingy `resolveActionWithStringParam` because it is more robust, specifically
            // it can handle /tags/something while the old one couldn't
            $action = $router->resolveActionWithIntegerOrStringParam($routePath, $request, 'hi', Tinhte_XenTag_Constants::URI_PARAM_TAG_TEXT);

            if (preg_match('/^page-(\d+)$/', $action, $matches))
            {
                // supports matching /tags/text/page-n links
                $request->setParam('page', $matches[1]);
                $action = 'view';
            }
        }
        return $router->getRouteMatch('Tinhte_XenTag_ControllerPublic_Tag', $action, 'tags'); <--- added this router before the other one
        return $router->getRouteMatch('Tinhte_XenTag_ControllerPublic_Tag', $action, Tinhte_XenTag_Option::get('majorSection'));
             
    }
 
#7
Okay i think I get it. 'majorSection' is the forum tab so if i just comment that out and replace it with the one above I guess it's the same, except that it now changes to tags. Thanks a lot for the help, at least now I know how routes work in xenforo