Are there any Domain Access $variables that can be used in page.tpl.php, or template.php for theming purposes?

Comments

agentrickard’s picture

There is data available, but not prepared for you.

Do this in template.php:

global $_domain;

This will hand you an array of information about the current domain. So then you do something like:

function template_preprocess_page($vars) {
  global $_domain;
  $vars['domain_name'] = check_plain($_domain['sitename']);
}

This will hand you a $domain_name variable for use in the template.

You can also use hook_domainconf() to create variables per-domain that are accessible through variable_get(). And you can use domain_domains() to get information about all domains.

yt2s’s picture

Exactly what I was looking for. Works like a charm. Thank you very much!

yt2s’s picture

For anyone who is interested...

I modified to suite the needs of my theme and added to the code above, (based on Step 1 of this post) to clean up the output to use as a CSS class in page.tpl:

<?php
function clean_class($string)
{
    $replace_chars = array("&", ":", ",", "'", "!");
    $cleanString = htmlspecialchars_decode( strtolower(trim($string)), ENT_QUOTES );
    $cleanString = str_replace($replace_chars, "", $cleanString);
    return str_replace(' ', '_', $cleanString );;
}
function mythemename_preprocess_page(&$variables) {
	global $_domain;
	$variables['domain_class'] = check_plain($_domain['sitename']);
		$dClass = clean_class($variables['domain_class']);
		$variables['domain_class'] = $dClass;
}

?>

$domain_class can now be used to print a class, based on the domain, in page.tpl.

Hope this helps someone.

Thanks again agentrickard This has really been helpful.