ted serbinski – a blog about drupal, macs, productivity, health, and bmws

a blog about drupal, macs, productivity, health, and bmws

Hot Swapping of Drupal Themes

At the ParentsClick Network we are soon to be rolling out many more sites on our platform. Because of our unique community API (which I will be detailing in a future post) we are running many sites (many not yet released) on the same install of Drupal, with the same database, and no shared tables. Yes, no typos there. More on just how that works in a later post.

One thing we have to do is change the theme based on the URL, along with a host of other things. ZivTech recently posted about changing themes, but for our setup, we need something more low level. Hence this technique.

Edit your settings.php and stick this in at the bottom:

// if the URL is an administration page
if (strpos($_GET['q'], 'admin') === 0) {   
  $conf['theme_default'] = 'garland';
}

What this does is tell Drupal to load an entirely different theme then the default one. Bonus points if you noticed the Drupal 5 administration theme bug: it shows the admin theme but if you save any form, the theme switches from the admin one to the default one. The above snippet fixes that.

The only catch? Make sure you initialize this in your system table by visiting the themes page and make sure you theme is in the sites/all directory. Otherwise you can run into some funky issues.

Happy theme hot swapping!

5 comments

 
Drupal Theme Garden (not verified) wrote 15 weeks 3 days ago

Nice idea.

Maybe your could be improved with some checks – in order to be sure that “default” theme exists.

 
Tobi (not verified) wrote 15 weeks 3 days ago

Hi,

do you use the Domain Access Module for all your sites?!

Looking forward to read how you realise that ;)

Tobi

 
Visitor (not verified) wrote 15 weeks 3 days ago

does that last slash cause problems for the /admin page? seems like it would not match. -moshe

 
ted wrote 15 weeks 3 days ago

@Tobi – no, not using Domain Access :)

@Moshe – ah yes, thanks, good catch, forgot to test that on the root admin page

 
stephthegeek (not verified) wrote 14 weeks 5 days ago

Oooh, handy, and simple! That bug always, er, bugged me.

Add your comment

The content of this field is kept private and will not be shown publicly.
  • You can use Textile markup to format text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <img> <pre>

More information about formatting options

Subscribe to updates

don't worry, spam free!

Recent comments