Our site will be undergoing a redesign and renaming in the near-future, so instead of typing out the website's name in the node content, I'd much rather use the $site_name variable to reduce the amount of work I have to do when we rename the site. However, when I try to use $site_name in a block's content, it fails.

This code excerpt:

global $site_name;

if($site_name)
print $site_name;

else
print 'no site name';

returns 'no site name', even though there is a site name defined under /admin/settings/site-information The $site_name variable works perfectly in the header section of my page.tpl.php, so I have no idea what's causing it to be empty in the content section of the same page.

Comments

nevets’s picture

$site_name is only implemented for page.tpl.php and is not a global.

To get the site in the block body you could use something like

$site_name =  variable_get('site_name', 'Drupal');