Thanks for this episode.
Our site (ThemeGarden) use this module (+ some our code) for browsing themes.
Drupal 7 SwitchTheme module
Share with Others
The Drupal 7 SwitchTheme module creates a simple block that allows a user to easily switch between different themes on a Drupal 7 website. This allows other users (not just administrators) to view the site in a different theme. This is set on a per user basis, so one user can view the site in a different theme than another user.
In this episode you will learn:
- How to configure the Drupal SwitchTheme module
- How to set permissions and use the SwitchTheme module for users besides administrators
Thanks to ModuleNotes.com for sponsoring this episode of the Daily Dose of Drupal.
Hello everybody and welcome to another episode of the Daily Dose of Drupal. Today we’re on Episode Number 132 and we’re going to be going over the Switch Theme Module.
The Switch Theme Module basically creates a block that allows you to switch back and forth between themes on your Drupal site and this is very useful if you want to allow users to change the look and feel of your site if you have multiple themes, it’s also good for some testing purposes if you want to try out a bunch of different themes easily.
So we’re going to go ahead and give that a look but before we do; as always I’m Shane Thomas, you can follow me on Twitter at smthomas3, also go to codekarate.com if you haven’t already and sign up for the newsletter down here on the bottom left and also click on this support code karate link over here and learn how you can help support code karate in my vision of providing Drupal education for everyone for free. Today’s sponsor is modulenotes.com.
Modulenotes.com is a great place to go if you want to learn about Drupal modules, basically it provides module descriptions that are in simple terms, easy to understand. On top of module descriptions they also have videos for the modules pulled in from a whole bunch of different sites and other different types of descriptions so g ahead and check out some of the modules here and you’ll notice there are quite a few code karate videos that are pulled in to the site as well so go ahead and take a look at modulenotes.com.
Let’s go ahead and get started; I already have the Switch Theme module installed so I’ll take a look at that. The first thing we’re going to do is we’re going to click on the permissions page and I’m going to look for the switch theme permissions and I’m going to go ahead and give anonymous users the ability to switch themes.
I want them to be able to easily switch the themes on the site, it could give it to an authenticated user as well, you can also allow them to permanently use a custom theme, that type of thing but we’re just going to work on just the search themes and covert that so I’m going to save that and now I’m going to come back to the modules page, I can also go to the admin menu to get here but I’m going to go to the configure option. You’ll notice that when I click on configure I have three options here; Bartik, Seven and Zen.
So basically these are the three themes enabled on my site. If I open up in a new tab you can see that I have Bartik installed, Seven installed and Zen installed. If I wanted to enable another one, let’s say we want to enable Garland as well we can enable that, refresh this page and you can see Garland shows up I can of course give this a different name so if I want to change Seven to say, Admin Theme instead of Seven I can do that, save it and basically these are just user friendly names for your different theme options. After is saved that the next step is to of course to add the block.
So I’m going to come into the blocks page and I’m actually going to hide a few of these blocks just to lower or simplify a little bit, I’m going to scroll down into the bottom and find the Switch Theme Block and I’m going to move that into sidebar first. Start to come up and you’ll see we have the Switch Theme Block, I’ll move it up just below the search form and I’m going to go ahead and save this page. Just to make sure; I’m also going to set that in the sidebars of these other themes as well.
That way when I change themes it still going to be showing up in the same place or relatively close to the same place so for the Garland save it, the same for Seven, let’s put that in the top of the content section and I’ll go ahead and give it a test. I’ll go ahead and leave Zen without it for now. Now you can see that I have a little theme switcher here so I can go ahead and click on Garland and click Switch.
You’ll notice that my theme completely changes, I didn’t have to go to the appearance tab, you can switch to Seven and it switches, I can of course go back. But the important thing is it’s not … obviously this can be a tool used for administrators to easily switch between themes but often it would be used to allow your users to select how they want to view your site.
So if you wanted to have multiple themes on your site and you wanted your users to be able to choose the different themes and maybe you had a couple of different color options in your different themes and you wanted them to be able to choose how they wanted to view your site, you can use a different accessibility reasons to allow certain themes to be easier to read than others, more accessible than the default ones, maybe larger font in certain themes but we’re going to go ahead and show how that can work if I logout.
So you can tell them in logout no admin menu at the top and I of course can switch the theme as an anonymous user. This of course would work with authenticated users or any user role that you gave the Switch Theme permission. You will notice if I go to Zen now I’m kind of at the stuck point because now that I’ve switch the theme and I don’t have a block in that spot I can of course switch the theme back so I would of course need to login and then of course I could change the theme.
So as you can see it’s very easy to allow users to switch between the different enabled themes on the site, you can also look at the readme file for instructions on how to modify single theme and use the Switch Theme to allow users to choose small, medium and large text versions of your site.
So a pretty handy little module, really simple on what it does. Go ahead and check it out and see if something you can use on your next Drupal projects. Thanks again to modulenotes.com for sponsoring this episode of the Daily Dose of Drupal and thanks for watching, we’ll see you next time.
Find out what you're missing with our 5 Secrets to becoming a Drupal 7 Ninja
Thanks for this episode.
A word of warning when using this module: if you are not logged in and you switched the theme then the theme is only there for the page on which you switched. For more info on this error in this module see: http://drupal.org/node/1645504
Do you have any experience when combining Mobiliser and SwitchTheme?
I am using mobilizer module to create a mobile theme and would like to use Switchtheme to give users an option to use the desktop theme instead on their mobile devices if they choose.
Problem is when switching to the Mobilizer theme, the list of options in SwitchTheme is a list of one. Just the Mobilizer theme. So now we can't switch back.
All the other enabled themes switch fine, giving full lists.
Are you aware of any Theme settings that would disable the list_themes() function to give a restricted list?