ted serbinski – entrepreneur & web architect
  • thoughts
  • about
  • contact



Popular content

  • RightScale & Drupal - How to Get Internal IP Address
  • 2nd Annual "Cookbook for Moms"
  • SimpleFeed 1.0 ships!
  • Yale School of Drama
  • 2 Guys Uncorked launches!
  • New iPod
  • Gorgeous wallpapers
  • How to Keep a Macbook Cool
  • Connecting Drupal and Silverlight
  • SimpleFeed
more

Recent comments

  • This is a very nice tutorial
    2 days 23 hours ago
  • Yes that would wor
    6 weeks 17 hours ago
  • I’m Thanks
    6 weeks 17 hours ago
  • I’m Thanks
    6 weeks 17 hours ago
  • trial New to your blog.
    7 weeks 3 days ago
more

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:

  1. // if the <span class="caps">URL</span> is an administration page
  2. if (strpos($_GET['q'], 'admin') === 0) {    
  3.   $conf['theme_default'] = 'garland';
  4. }

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!

posted 19 Jun 2008
  • code
  • drupal
  • ParentsClick

8 comments

#1
Drupal Theme Garden wrote 3 years 48 weeks ago

Nice idea.

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

#2
Tobi wrote 3 years 47 weeks ago

Hi,

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

Looking forward to read how you realise that ;)

Tobi

#3
Visitor wrote 3 years 47 weeks ago

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

#4
ted wrote 3 years 47 weeks ago

@Tobi – no, not using Domain Access :)

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

#5
stephthegeek wrote 3 years 47 weeks ago

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

#6
open-keywords wrote 3 years 29 weeks ago

Thanks for this hint, which actually fixes the Administration theme bug when submitting forms (really annoying one)

#7
open-keywords wrote 3 years 29 weeks ago

Well, testing further, it brings some bugs as side effect: I was using additional regions in my front end theme, and since this change, they don’t appear anymore in /admin/build/block : the theme files isn’t parsed looking up for regions.

#8
open-keywords wrote 3 years 29 weeks ago

See http://drupal.org/node/242200 for a better alternative (while should be considered as a bug with a proper fix)

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.
  • 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>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options


Code examples and downloadable zip files of code are licensed under a Creative Commons License.
All other content, unless where noted, ©2012 Theodore Serbinski. All Rights Reserved.