Here are a couple of solutions I've used when using the Domain Access module and have needed some domain specific variables. For these examples we'll assume that you are using these two domains - www.site-a.com and www.site-b.com
1) Get the domain machine name
This is the method I prefer and it will print out something like site_a_com or site_b_com.
This is the machine name given to your domain when setup in your Domain Access settings. To find out or set the machine name go to '/admin/structure/domain' and edit a domain - the machine name appears next to the domain name field.
<?php $domainGet = domain_get_domain(); $domain = $domainGet['machine_name']; print $domain; ?>
2) Use standard Drupal Global variables
You could use the cookie domain to variable. The below would print out .site-a.com or .site-b.com depending which site you are on:
<?php global $cookie_domain; print $cookie_domain; ?>
I think you might also be able to use the global $base_root; variable, but will need to check.
3) Use the actual Domain Access variable global $_domain
$_domain is the 'official' global variable for the Domain Access module, but this is rendered as an array so can't be used out-of-the-box. Here is a post describing how you can add it to your template.tpl.php file in order to create a usable global variable. Since the the pervious methods worked for me I've not actually tried it.

Justin Chevallier
Avid Drupal site builder & user for +10 years.
Add new comment