XF 2.3 How to highlight nav Tab and make sublinks appear in secondary navigation?

Alpha1

Well-known member
Licensed customer
I have a lot of major addons. Each of the addons had a navigation tab. As almost no one will horizontally scroll through 20 navigation tabs, these navigation tabs were pointless. So I decided to create a few new navigation tabs and made these the parent of the existing navigation tabs.

Under the Community tab, I now have these applications:
  • Calendar
  • Chat
  • Forum
  • Journals
  • Media
  • Social Groups
Each of these addons has sublinks that normally appear in the secondary navigation (desktop) if the user visits the addon.
But this no longer works.
The Community tab is not highlighted is the user visits one of the addons. :(

I'm using @Russ PixelExit style and @bzcomputers Menuflex and @Matt C. Content Tabs addons to remove some of the clutter.

Does anyone know the answers to these questions:
  1. How do I make the sublinks for the visited addon appear in secondary navigation?
  2. How do I make the Community tab the selected tab if the user visits any of the above addons?
  3. Is there a way to get Collapsible 2nd level entries in the off-canvas mobile menu?
Thanks in advance for any tips and help.
 
This is a common challenge when reorganizing navigation tabs under a single parent. Here's how to address each of your questions:

1. Sublinks in secondary navigation:
When you nest addon tabs under a custom parent like "Community", the secondary navigation (sub-nav bar below the main tabs) won't automatically pull in the sublinks from each addon. That's because each addon registers its own secondary nav entries tied to its own top-level tab, and reparenting breaks that link.

The most reliable fix is through the navigation_macros_setup template. You'd create a template modification that registers the addon sublinks under your Community tab's navigation section. Something like:

Code:
<xf:set var="$extraTabs">
  <xf:if is="$selectedTab == 'calendar' OR $selectedTab == 'chat' OR $selectedTab == 'forums' OR $selectedTab == 'xfmg' OR $selectedTab == 'journals' OR $selectedTab == 'socialGroups'">
    <!-- merge sublinks here -->
  </xf:if>
</xf:set>

However, the exact implementation depends on how MenuFlex and Content Tabs handle the nav structure. You may need to check with @bzcomputers and @Matt C. if their addons expose a way to programmatically assign the parent tab context.

2. Highlighting the Community tab:
The tab highlight is controlled by the selectedTab variable that each controller sets. When you visit the Media section, XenForo sets selectedTab = 'xfmg', not your custom Community tab ID.

You can fix this with a code event listener on templater_template_pre_render that checks if the current selectedTab is one of your child addons, and if so, overrides the navigation state to highlight Community. Alternatively, a simpler CSS approach:

Code:
.p-nav-list .p-nav-el--community {
  /* always style as active when any child addon page is visited */
}

body[data-template^="xfmg_"] .p-nav-list .p-nav-el--community,
body[data-template^="calendar_"] .p-nav-list .p-nav-el--community {
  color: var(--nav-tab--active-color);
  background: var(--nav-tab--active-bg);
}

You'll need to adjust the data-template selectors to match each addon's template prefix.

3. Collapsible 2nd level on mobile:
XenForo's off-canvas mobile menu doesn't natively support collapsible sub-entries for custom grouped tabs. This would require JavaScript to convert the flat list into an accordion-style menu. MenuFlex might already handle some of this — worth checking if there's a mobile collapse option in its settings.

If not, you could add a custom JS handler that targets the off-canvas menu entries and toggles a is-active class on click to show/hide children.
 
Back
Top Bottom