Adding your own buttons to Subs.php

Started by Mathesar, September 01, 2014, 03:20:21 PM

Previous topic - Next topic

Mathesar

Hello SMF Community,

This is my first official post here, hurrah! I am in desperate need of some help and after extensive searching I yet to find anyone able to provide a detailed solution. Here's my challenge: when I create my own custom navigation buttons using the same techniques found > here < it functions perfectly as intended. The only thing I am having difficulty integrating is that when I click on any of the custom navigation buttons I created, even though it still takes me to the correct location I specify in href the active button indicator automatically high-lights the "home" button rather then button I had just selected. I hope that make sense. As an arbitrary example if you look at the navigation buttons such as "home","help", "search" etc. when you click any of them they take you to that href location and as a result that button has some kind of visual cue that tells the user that is where they are. But say I added my own button to that array titled "media" linked to an external custom page (using this format here) and when I click on that it takes me to that custom page and everything shows correctly headers footers, navigation bar, etc except the "home" button is high-lighted not the "media" button. Please can anyone in detail provide me with a step-by-step way to integrate my custom buttons so the have the same visual behavior as the standard smf buttons? I know this can be done because when I added tinyportal to my forum that button was added to my navigation bar and has the desired visual behavior I am looking for on my custom buttons.

kat

Welcome! I locked your other topic. No need for two. ;)

Let me find a link, for you... Won't be a mo.

Edit: Meh. Couldn't find it...

Is this happening with the SMF default theme? Or, are you using a custom theme?

NanoSector

Hi Mathesar, welcome to SMF!

Open up your Subs.php file, and under the array of buttons there's a snippet of code to determine the current action. However to write that up, we would need to know the button you created.

Can you post your button here, which you have created, in [code][/code] tags?
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."


Mathesar

Quote from: K@ on September 01, 2014, 03:29:50 PM
Welcome! I locked your other topic. No need for two. ;)

Let me find a link, for you... Won't be a mo.

Edit: Meh. Couldn't find it...

Is this happening with the SMF default theme? Or, are you using a custom theme?

I am using a custom theme, but I am assuming the way its implemented would be similar and independent of what themes were being used or not used, but correct me if I am wrong.

Mathesar

Quote from: NanoSector on September 01, 2014, 03:35:47 PM
Hi Mathesar, welcome to SMF!

Open up your Subs.php file, and under the array of buttons there's a snippet of code to determine the current action. However to write that up, we would need to know the button you created.

Can you post your button here, which you have created, in [code][/code] tags?

I would be more then happy to drop in the buttons I added however I am currently at work for the next 3 hours and wont have access to my Subs.php file until then. But I will post it as soon as I get home this evening. This is great that you guys respond so fast...

kat

I believe that you're right, in most cases. But, I think that some themes use their own code (Helios springs to mind).

Knowing which theme you use might be of help.

It might not, though, as Nano seems to have an idea. :)

Mathesar

Quote from: K@ on September 01, 2014, 03:48:50 PM
I believe that you're right, in most cases. But, I think that some themes use their own code (Helios springs to mind).

Knowing which theme you use might be of help.

It might not, though, as Nano seems to have an idea. :)

I had a 3 month paid membership with DzinerStudio that allowed me to download their themes, after such I cancelled my membership so I don't have access to their support forums. But I a using their Gearbox theme.

NanoSector

That's fine, I'll take a look tomorrow if someone hasn't beaten me to it. :)

Quote from: K@ on September 01, 2014, 03:48:50 PM
I believe that you're right, in most cases. But, I think that some themes use their own code (Helios springs to mind).

Knowing which theme you use might be of help.

It might not, though, as Nano seems to have an idea. :)
I think you're confusing SMF 1.1 and 2.0 here.

Since 2.0, all the buttons have been put in Subs.php, which are then passes to the theme and SMF doesn't get involved in how it's put on the user's screen.
In 1.1, however, the buttons were all hard-coded in each theme installed. This caused a number of issues, the worst probably being inconsistency.

If you installed a mod, it had to add the same button in every theme. As you might guess that will cause issues as not every theme has the same code installed to it. And on top of that, if the mod installed the button might pop up in different places in each different theme, some buttons would miss in themes, and to top it off, if you installed a new theme, all your custom buttons would not be there.
This was all fixed in 2.0 by moving the buttons to a central place, namely Subs.php. There, the code is consistent, so mods can easily add buttons, and it's consistent for themes too, since the buttons are always passed (unless the execution is modified by a mod) in the same order, and all buttons will appear everywhere, even in custom themes.

If a theme doesn't obey this "rule", it would not get accepted at our theme site. So, it should theoretically not matter what theme you're using in 2.0. But there are always exceptions, though I doubt many exist at our theme site (if any).

Quote from: Mathesar on September 01, 2014, 03:55:01 PM
I had a 3 month paid membership with DzinerStudio that allowed me to download their themes, after such I cancelled my membership so I don't have access to their support forums. But I a using their Gearbox theme.
Dzinerstudio's theme usually obey this rule, unless you accidentally got a 1.1 theme (in which case, it shouldn't even run on 2.0).
Although, if the button appeared if you put it in Subs.php, then yes your theme is "obeying" this "rule".
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

kat

Yeah, I understand that. :)

I thought the v2 version of Helios did things in a different way, though, especially as it has boxes for adding custom buttons.

I could well be wrong, though. You know way more about this than I do. :)


Mathesar

no its a 2.0 theme, everything works and looks correct. I can see all the buttons and sub menu buttons I added just the cosmetic thing needs to be implemented. I had my suspicion it had something to do with some action registration.

kat

Yeah. The version of Helios that I have is, too.

But, don't put too much store in what I said, coz I could well be wrong. ;)

NanoSector

Helios applies some clever tricks, to add in custom buttons. It however still applies to the whole thing I put up above :)
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."


Kindred

The thing is, the new buttons can only tigger the highlight if the action is in the action array...   If you are linking to other pages which are not represented in the action array, then you'll have to add some custom coding to deal with each situation.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

NanoSector

Quote from: Kindred on September 01, 2014, 05:26:09 PM
The thing is, the new buttons can only tigger the highlight if the action is in the action array...   If you are linking to other pages which are not represented in the action array, then you'll have to add some custom coding to deal with each situation.
That's why I asked for the button before :)
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Advertisement: