Skip to content

Instantly share code, notes, and snippets.

@mkorostoff
Created May 11, 2012 15:06
Show Gist options
  • Save mkorostoff/2660330 to your computer and use it in GitHub Desktop.
Save mkorostoff/2660330 to your computer and use it in GitHub Desktop.
Preprocessor function to add body classes
<!DOCTYPE html>
<!--[if IEMobile 7]><html class="iem7" <?php print $html_attributes; ?>><![endif]-->
<!--[if (lte IE 6)&(!IEMobile)]><html class="ie6 ie6-7 ie6-8" <?php print $html_attributes; ?>><![endif]-->
<!--[if (IE 7)&(!IEMobile)]><html class="ie7 ie6-7 ie6-8" <?php print $html_attributes; ?>><![endif]-->
<!--[if (IE 8)&(!IEMobile)]><html class="ie8 ie6-8" <?php print $html_attributes; ?>><![endif]-->
<!--[if (gte IE 9)|(gt IEMobile 7)]><!--><html <?php print $html_attributes . $rdf_namespaces; ?>><!--<![endif]-->
<head>
<?php print $head; ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="MobileOptimized" content="width">
<meta name="HandheldFriendly" content="true">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="cleartype" content="on">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<title><?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body class="<?php print $body_classes ?>"<?php print $attributes; ?>>
<div id="skip-link">
<a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
</div>
<?php print $page_top; ?>
<?php print $page; ?>
<?php print $page_bottom; ?>
</body>
</html>
<?php
/**
* Override or insert variables into the html templates.
*/
function rsn_base_preprocess_html(&$vars) {
/* Makes the 'body_classes' variable available in html.tpl.php. Contains the following:
* Default classes -> front, not-front, logged-in, not-logged-in, node-type-[type];
* ˜◘ User ID -> uid-[#], shows uid-0 for anonymous users;
* ◘ User roles -> authenticated user, administrator, content editor, etc(an oddity here—I haven't bothered collapsing
* spaced into dashes, so the CSS selector for an authenticated user is .authenticated.user not .authenticated-user);
* ◘ URL arguments -> for instance, the page csnwashington.com/video has the body class 'video'.
* Node pages (csnwashington.com/node/123) have classes 'node' and '123')
*/
$vars['body_classes'] = implode(" ",$vars['classes_array']) . " uid-" . $vars['user']->uid . " " . implode(" ",$vars['user']->roles) . " " . implode(" ",arg());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment