This recipe demonstrates how we can go about controlling the theme being used to render a page from within a module. As an example, we will be adding the code that allows the rotation of themes based on the day of the week.
As we have seen in other recipes in this chapter, a number of sites use an "odds and ends" module to handle tweaks and customizations particular to the site. We will be using the mysite.module
created earlier in this chapter to hold our customizations. It is assumed that the module is available and already enabled.
Open the mysite.module
file and paste the following code in it:
/** * Implements hook_custom_theme(). */ function mysite_custom_theme() { // An array of themes for each day of the week. // These themes have to be installed and enabled. $themes = array(); $themes[0] = 'garland'; $themes[1] = 'bartik'; $themes[2] = 'stark'; $themes[3] = 'seven'; $themes[4] = 'mytheme'; $themes...