Allowing users to choose from multiple themes
This recipe details the steps involved in enabling users to choose which theme they wish to use when they are viewing the site. For example, users with accessibility issues might prefer to view the site using a high-contrast theme, or those viewing the site via monitors with low resolutions might prefer a theme which uses a fluid layout.
Drupal's flexible approach to themes includes the ability to allow theme-specific block arrangements. As a result, this allows us to, for example, have a separate theme for site contributors with, perhaps, an extra sidebar equipped with a contributor-specific block arrangement.
Getting ready
Since we are going to be working with multiple themes in this recipe, we will need at least two themes to have been enabled on the site. This can be done via the theme administration page at admin/build/themes
(Home | Administer | Site building | Themes) as seen earlier in this chapter.
How to do it...
We can enable users to choose between the different themes which are available through the following steps:
Navigate to
admin/user/permissions
(Home | Administer | Users | Permissions).Scroll down to the section titled system module dealing with system-level permissions.
Check the box labeled Select different theme for the authenticated user role.
Click on the Save permissions button to save our changes.
Now, visit the My account page at the path
user
and click on the Edit tab at the top.Locate the newly available section titled Theme configuration.
Choose the preferred theme by selecting the associated radio button as in the following screenshot:
Click on the Save button at the bottom of the page to register our changes.
How it works...
Drupal saves the users' choice as a configuration setting in the database. When a page is to be displayed, Drupal notices this setting and themes the page using the specified theme instead of the site's default theme.