Setting custom menu button active

Started by DeadMan..., March 21, 2023, 04:55:05 PM

Previous topic - Next topic

DeadMan...

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)
I tell it how I see it... Don't like it? Hit Alt+F4!

Arantor

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.

DeadMan...

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.
I tell it how I see it... Don't like it? Hit Alt+F4!

DeadMan...

Anyone have another idea how to accomplish this?
I tell it how I see it... Don't like it? Hit Alt+F4!

Arantor

Well it might have helped if you'd mentioned you had a portal messing with things...

DeadMan...

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():

I tell it how I see it... Don't like it? Hit Alt+F4!

Arantor

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?

DeadMan...

#7
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

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';
I tell it how I see it... Don't like it? Hit Alt+F4!

Arantor

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.

DeadMan...

I tell it how I see it... Don't like it? Hit Alt+F4!

Arantor

Oh, I'm an idiot.

Make that an if rather than an elseif.

DeadMan...

Quote from: Arantor on March 23, 2023, 04:05:10 PMMake that an if rather than an elseif.

That did it. Thanks, my friend!
I tell it how I see it... Don't like it? Hit Alt+F4!

Sesquipedalian

I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Arantor

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.

DeadMan...

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?
I tell it how I see it... Don't like it? Hit Alt+F4!

Arantor

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.

Advertisement: