Hello All, I was wondering if it is possible to run multiple themes on a single instance of Drupal. Possibly, based on the content type, it would use a different theme. If this is possible, which modules would I have to install for it to work? For instance, lets say I have a company, but there are two divisions in the company. I want the main companies website to have one look, then the two divisions to have their own look. I wouldn't want to run 3 instances of Drupal to accomplish this, so I imagine there is a way to do this, just not sure. Any input is greatly appreciated!

Thanks,
Shane

Comments

WorldFallz’s picture

I'm not aware of any modules the enable completely separate themes, but you can easily change the entire layout of a theme by content type, thus retheming it, simply by creating and editing page-.tpl.php files in your theme's directory. node-.tpl.php files are also available if you just want to change the node portion of a page.

shanefjordan’s picture

Thank you, I see how to do this in "creating a separate admin theme" with the following code:

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      if ((arg(0) == 'admin')) {
        $vars['template_file'] = 'page-admin';
      }
      break;
  }

  return $vars;
}

I thought that the $hook was giving the content type. But, I added this code and I get the same content type of page, regardless of the page i'm on. I have different content types setup, and would have thought that I could of see the content type. So, then I would have been able to do:

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'companymain':
        $vars['template_file'] = 'page-main';
        break;
    case 'companya':
        $vars['template_file'] = 'page-companya';
        break;
    case 'companyb':
        $vars['template_file'] = 'page-companyb';
        break;
  }

  return $vars;
}

Anyone have any ideas as to why the $hook is constantly returning page?

- Shane

shanefjordan’s picture

I found some other code, that looks like it should work.

function _phptemplate_variables($hook, $vars) {
  switch ($hook) {
    case 'page':
        $vars['template_file'] = $vars['node']->type;
        break;
  }
  return $vars;
}
shanefjordan’s picture

When I am using this code, I changed it so that $vars['template_file'] = 'page-'.$vars['node']->type (so it has the page prefix that is requires). The problem i'm having is that even though I am setting the template_file, it calls my template for each region I have created. So, the page gets all messed up. I feel like this is so close, but just have something small that I'm missing or I'm completely doing something wrong.

Thanks,
Shane

WorldFallz’s picture

I'm still not sure I'm fully grokking what you're trying to do. "page-<contenttype>" is already built-in to drupal 5 and that looks like what this code is doing. You no longer need to do that in D5.

There is a d5 core feature for using a different theme for admin pages, but "admin" isn't a content type so I'm guessing it must be path based ( */admin/* )

If you simply want a "page-companya.tpl.php" and "page-companyb.tpl.php" all you need to do is create them... they will be automatically discovered and used for those node types.

shanefjordan’s picture

I just tried creating the new page- file and it didn't seem to pick up the page-companya.tpl.php template. It just continues to use the default page.tpl.php template. But, that is definitely what I am trying to do. If it is supposed to be built in, i'd love to use the functionality rather than have to write my own to do this. I'm running 5.6

WorldFallz’s picture

ok, it appears the book page on this topic is a little misleading:

The PHPTEMPLATE Engine for Drupal 5.x has a new feature that automatically loads page-layout.tpl.php files as soon as you upload them to your active theme folder. In other words, if you upload a page-blog.tpl.php file to your active theme folder, you don't need to tell template.php.

It seems you also have to provide a suggestion to the phptemplate engine in the _phptemplate_variables function in the template.php file for your theme:

function _phptemplate_variables($hook, $vars = array()) {
  if ($hook == 'page' && (arg(0) == 'node' && is_numeric(arg(1)))) {
    // Load node and pull it's type placing it in a suggestion.
    $node = node_load(arg(1));
    $vars['template_file'] = 'page-'. $node->type;
  }
}

If you already have a _phptemplate_variables function in the template.php file for your theme, you'll have to merge the IF statement into it.

I just tested it on D5.3, and it worked for me.

It's such a small yet useful change, I'm surprised it's not already there.

WorldFallz’s picture

So, the problem with the function as you wrote it, was that $hook != content type, but rather theme function being called.

paulnem’s picture

http://drupal.org/project/taxonomy_theme

Taxonomy theme is something worth looking into. You can change your theme based on various options, one of which is path. If you were to split your site by path, then it's easy to change the theme for each section.

site.com/blah/* <-- theme 1
site.com/boom/* <-- theme 2

geshan’s picture

You can do it with sections module, look here on how to do it.

have fun.

judef’s picture

Instead of using sections we can do it easily by using themekey module

http://drupal.org/project/themekey