I have Drupal multisite, where I have three different sites. THey all use same theme. Now I would need to do small changes to templates that only visible on some sites. How can I tell on template level that what site is used.

For example on site 1's front page I would like to have:

Some content

But then on site 2's front page I dont want that div to be showed at all. Can I achive this somehow? Is theere "native" way to find out thie right site inside template, maybe in template.php?


4 Answers 4


i would suggest doing multiple themes, one per site/group of sites - where they all have a common theme as parent.

that way you can overwrite specific elements on individual sites without having to worry about adding all the logic to check what site your currently rendering content for.


You may try to use this code. It worked for me perfectly in similar situation

// Allow a site-specific user defined CSS file (useful for multisite installations):
// If a CSS file "local-[SITE].css" is residing in the "css" directory (beside "local.css"),
// it will be loaded after "local.css". SITE is the site's host name, without leading "www".
// For example, for the site http://www.mydomain.tld/ the file must be called called "local-[mydomain.tld].css"
global $base_url;
$site = preg_replace("/^[^\/]+[\/]+/", '', $base_url);
$site = preg_replace("/[\/].+/", '', $site);
$site = preg_replace("/^www[^.]*[.]/", '', $site);
drupal_add_css(path_to_theme() . '/css/local-[' . $site . '].css', 'theme', 'all');

Since they're using the same theme you could use a condition based on the alias or full path. Hope that helps.

  • Isn't there really any drupal variable or proper way doing this? Not even d7?
    – user995317
    Commented Oct 26, 2011 at 9:14
  • Hmmn I've used this particular solution before but there must be another way of doing this which I'd like to learn too :)
    – zarsiwala
    Commented Oct 26, 2011 at 15:26

I am not sure if it has anything to do with what you are looking for, but couldn't you just add a condition on $base_url variable?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.