Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: shawnb61 on June 21, 2022, 09:30:11 PM

Title: SMF Theme Toggle
Post by: shawnb61 on June 21, 2022, 09:30:11 PM
Link to the mod (https://custom.simplemachines.org/index.php?mod=4336)

Description:

The SMF Theme Toggle mod lets you easily toggle between the forum default theme and an admin-designated secondary theme with a single click.

This mod works with any theme that allows new entries in the main & profile menus.

This mod works whether or not javascript is enabled on the client.

The requested change is persistent; it works by updating the user's requested theme on their profile.  Users must be allowed to select themes.

Note that menus are cached; you may need to clear cache for this mod to take effect.

Releases:
 - v1.0 Initial release
 - v1.1 Allow admin to select profile menu or main menu
Title: Re: SMF Theme Toggle
Post by: Steve on June 22, 2022, 08:57:10 AM
Very nifty Shawn.

Can you consider making it so each member can toggle between their two favorite themes in a future version?
Title: Re: SMF Theme Toggle
Post by: shawnb61 on June 24, 2022, 12:55:45 PM
Yep, that's a definite maybe!

The other suggestion I've received is placing it on the profile menu vs the main menu, or making the location an option.

The point was to make it easy to switch to dark mode, in one click, as I've seen on some other sites.
Title: Re: SMF Theme Toggle
Post by: FrizzleFried on June 24, 2022, 01:34:57 PM
I know this is beyond the scope of the current iteration... but would you consider perhaps allowing more than just a toggle between two themes?  My forum runs a total of 5 themes... clicking that button and providing a drop down to select between them would make this mod a 'must have' for my forum...

Just something to consider.

It does work nicely as advertised already.  Thank you.
Title: Re: SMF Theme Toggle
Post by: Steve on June 24, 2022, 01:56:23 PM
That would make the mod a theme changer rather than a toggle between two themes, yes?  :)
Title: Re: SMF Theme Toggle
Post by: FrizzleFried on June 24, 2022, 02:08:19 PM
What is a toggle other than a theme changer but for two themes?

 8)
Title: Re: SMF Theme Toggle
Post by: Arantor on June 24, 2022, 02:11:51 PM
And that's the point, toggling between two things only.

There are theme changer mods out there, either standalone or part of the portal mods.
Title: Re: SMF Theme Toggle
Post by: FrizzleFried on June 24, 2022, 03:38:09 PM
...but none as elegant.  Again...`twas just a suggestion.  FWIW, I run Tiny Portal currently for the sole reason of the theme changer.  Not elegant.
Title: Re: SMF Theme Toggle
Post by: marcosbr on June 24, 2022, 09:59:20 PM
Quote from: shawnb61 on June 24, 2022, 12:55:45 PMYep, that's a definite maybe!

The other suggestion I've received is placing it on the profile menu vs the main menu, or making the location an option.

The point was to make it easy to switch to dark mode, in one click, as I've seen on some other sites.

I like it
Title: Re: SMF Theme Toggle
Post by: marcosbr on July 30, 2022, 01:00:26 AM
Is there a way to allow visitors to change the themes? I'm alternating between light and dark.
Title: Re: SMF Theme Toggle
Post by: marcosbr on July 31, 2022, 05:22:13 PM
Quote from: shawnb61 on June 24, 2022, 12:55:45 PMYep, that's a definite maybe!

The other suggestion I've received is placing it on the profile menu vs the main menu, or making the location an option.

The point was to make it easy to switch to dark mode, in one click, as I've seen on some other sites.

I customized a "copy" of the curve2 theme in dark mode.
Original: https://amigosdaeletronica.com.br
Your MOD is excellent and works well on my official forum.
I would just like permission for visitors!
This image is the "tests" forum with change by the portal.
Test: https://amigosdaeletronica.com/

Title: Re: SMF Theme Toggle
Post by: marcosbr on July 31, 2022, 05:40:56 PM
I forgot the image

Capturar.PNG
Title: Re: SMF Theme Toggle
Post by: shawnb61 on July 31, 2022, 09:40:46 PM
I will look into guest support at some point.  I am in the middle of a few other things I'm looking at atm, so it might be a while.
Title: Re: SMF Theme Toggle
Post by: Steve on October 22, 2022, 06:44:11 AM
Quote from: FrizzleFried on June 24, 2022, 03:38:09 PM...but none as elegant.  Again...`twas just a suggestion.  FWIW, I run Tiny Portal currently for the sole reason of the theme changer.  Not elegant.
https://custom.simplemachines.org/index.php?mod=3356 - works perfectly and can be placed at the top or bottom of the forum. A small css change can make it centered as well.
Title: Re: SMF Theme Toggle
Post by: Julius_2000 on March 01, 2024, 06:47:17 AM
Hi,

I would like to place the theme tog button somewhere else in the menu (outside top dropmenu and thus the burger menu on mobile devices). But for the life of me,  I cannot find  where the themetog function is placed in which php file. I've looked into index.template, Display, and Subs.php to no avail. Any help would be appreciated!
Title: Re: SMF Theme Toggle
Post by: shawnb61 on March 01, 2024, 02:23:45 PM
Since this mod is 100% hooks, there isn't an update made to a theme file for you to tweak.  The arrays that contain the menu entries are manipulated directly via hook. 

The current approach is to update the main menu $buttons array via the integrate_menu_buttons hook:
https://github.com/sbulen/SMF-Theme-Toggle/blob/fb788b8f0ae1e4244ba123f5889e532d10527d5c/dist/Sources/ThemeToggleHooks.php#L39

I believe you will want to update the $profile_areas array via the integrate_profile_areas hook.

Then test the bejeebers out of it...
Title: Re: SMF Theme Toggle
Post by: shawnb61 on March 21, 2024, 08:12:13 PM
v1.1 of this mod allows you to place the theme toggle button in the user profile menu. 

At the moment, I'm having some challenges placing this new version on the customization site.

Until this is resolved, feel free to download v1.1 here:
Title: Re: SMF Theme Toggle
Post by: Julius_2000 on March 23, 2024, 06:03:33 PM
Thank you so much, @shawnb61, for making the effort adding it to the menu, really unexpected and appreciated!

I now realize, though, I might have been a bit imprecise in my "request" recently. My intention was to have the toggle button sitting next to the alert and pm buttons (bell & envelope) so it could be readily accessed on mobile, too, without requiring the user to go to a menu first - just like those two. I use Fontawesome icons for these, so it would fit quite nicely on a mobile screen.
Title: Re: SMF Theme Toggle
Post by: shawnb61 on April 06, 2024, 03:51:53 PM
Note you no longer need to use the link above.  The link to the mod will now allow you to download the latest version.