Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: DeadMan... on March 21, 2023, 04:55:05 PM

Title: Setting custom menu button active
Post by: DeadMan... on March 21, 2023, 04:55:05 PM
Okay, I'm setting up a board to be called from the menu.
I edited Subs.php and got the menu button as I want.
However, I'm having trouble getting it to be "active" when viewing that particular board.

Menu button:

            'gallery' => array(
                'title' => $txt['gallery'],
                'href' => $scripturl . '?board=8.0',
                'show' => true,
                'sub_buttons' => array(
                ),
            ),

Below, where states for doing active, I tried:

    elseif ($context['current_action'] == 'gallery')
        $current_action = 'gallery';

Also tried:

    elseif ($context['current_action'] == 'index.php?board=8.0')
        $current_action = 'gallery';

Still does the main forum button as active. (Using a portal)
Title: Re: Setting custom menu button active
Post by: Arantor on March 21, 2023, 05:27:40 PM
Try:

    elseif (empty($context['current_action']) && !empty($context['current_board']) && $context['current_board'] == 8)
        $current_action = 'gallery';

As for removing the category, find this in Load.php (your portal may have changed it, it's in loadBoard():

// Build up the linktree.
$context['linktree'] = array_merge(
$context['linktree'],
array(array(
'url' => $scripturl . '#c' . $board_info['cat']['id'],
'name' => $board_info['cat']['name']
)),
array_reverse($board_info['parent_boards']),
array(array(
'url' => $scripturl . '?board=' . $board . '.0',
'name' => $board_info['name']
))
);

Take out the:
array(array(
'url' => $scripturl . '#c' . $board_info['cat']['id'],
'name' => $board_info['cat']['name']
)),

This whole structure takes the existing linktree (home), adds category, adds board hierarchy then the current board all in one go, so you just need to remove the little bit of it that is the category name.
Title: Re: Setting custom menu button active
Post by: DeadMan... on March 21, 2023, 05:31:43 PM
Quote from: Arantor on March 21, 2023, 05:27:40 PMTry:

Code Select Expand
    elseif (empty($context['current_action']) && !empty($context['current_board']) && $context['current_board'] == 8)
        $current_action = 'gallery';


Didn't work. Still shows Forum as active.
Title: Re: Setting custom menu button active
Post by: DeadMan... on March 22, 2023, 08:17:40 PM
Anyone have another idea how to accomplish this?
Title: Re: Setting custom menu button active
Post by: Arantor on March 22, 2023, 08:52:25 PM
Well it might have helped if you'd mentioned you had a portal messing with things...
Title: Re: Setting custom menu button active
Post by: DeadMan... on March 22, 2023, 08:57:27 PM
Quote from: Arantor on March 22, 2023, 08:52:25 PMWell it might have helped if you'd mentioned you had a portal messing with things...

Umm... I did. And you even commented on it afterwards.  :D

Quote from: DeadMan... on March 21, 2023, 04:55:05 PMStill does the main forum button as active. (Using a portal)

Quote from: Arantor on March 21, 2023, 05:27:40 PMAs for removing the category, find this in Load.php (your portal may have changed it, it's in loadBoard():

Title: Re: Setting custom menu button active
Post by: Arantor on March 22, 2023, 09:17:57 PM
That was a subtle hint that it would be nice to not try to read your mind further than necessary... as in, all the useful details up front?
Title: Re: Setting custom menu button active
Post by: DeadMan... on March 22, 2023, 09:24:48 PM
Quote from: Arantor on March 22, 2023, 09:17:57 PMThat was a subtle hint that it would be nice to not try to read your mind further than necessary... as in, all the useful details up front?

Good point...

SMF 2.1.3 - TinyPortal 2.3.0
NameX theme (https://custom.simplemachines.org/index.php?theme=3003)

I had tried this, but it didn't work:

Quote from: Arantor on March 21, 2023, 05:27:40 PMTry:

    elseif (empty($context['current_action']) && !empty($context['current_board']) && $context['current_board'] == 8)
        $current_action = 'gallery';
Title: Re: Setting custom menu button active
Post by: Arantor on March 23, 2023, 02:48:31 PM
OK so I see how TinyPortal is doing this.

Give this a go instead.

    elseif ($context['current_action'] == 'forum' && !empty($context['current_board']) && $context['current_board'] == 8)
        $current_action = 'gallery';

Gets a bit different if you want to change it up based on whether they're actually in the board or not or in a topic in that board or not but in general this should work.
Title: Re: Setting custom menu button active
Post by: DeadMan... on March 23, 2023, 03:54:54 PM
Quote from: Arantor on March 23, 2023, 02:48:31 PMGive this a go instead.

Still not doing it.

https://www.deadmanknows.site/ (https://www.deadmanknows.site/)
Title: Re: Setting custom menu button active
Post by: Arantor on March 23, 2023, 04:05:10 PM
Oh, I'm an idiot.

Make that an if rather than an elseif.
Title: Re: Setting custom menu button active
Post by: DeadMan... on March 23, 2023, 04:12:45 PM
Quote from: Arantor on March 23, 2023, 04:05:10 PMMake that an if rather than an elseif.

That did it. Thanks, my friend!
Title: Re: Setting custom menu button active
Post by: Sesquipedalian on March 23, 2023, 07:53:13 PM
Quote from: Arantor on March 23, 2023, 04:05:10 PMOh, I'm an idiot.

Not in my experience. :)
Title: Re: Setting custom menu button active
Post by: Arantor on March 23, 2023, 08:34:29 PM
I should have seen it earlier to be honest, it's kind of a rookie mistake on my part - of course it would never trigger, because the first link in the chain (action being forum is a known action in the menu) would always have fired first and skipped all the branches.

Though I will be honest, I spend time over in Laravel land these days and I miss code like this, it has a certain fundamental honesty that Laravel doesn't.
Title: Re: Setting custom menu button active
Post by: DeadMan... on March 23, 2023, 09:22:04 PM
Quote from: Arantor on March 23, 2023, 08:34:29 PMI should have seen it earlier to be honest
Does that mean the first code you gave may have worked if we did if instead of elseif?
Title: Re: Setting custom menu button active
Post by: Arantor on March 23, 2023, 10:11:24 PM
Nah, it would still have failed because I didn't at that point realise that action=forum already was directly in play since not all portals do it that way. $context['current_action'] was never empty in that scenario.