Add role based class to body tag

Public

Add this to your template.php file for your custom theme to add classes to the body of the document that line up with the roles the current user has. This can be useful when you want to style / present content different based on who the user role but don't want to constantly check via PHP / module layers.

Get raw version
php
  1. /**
  2.  * Implements template_preprocess_html().
  3.  *
  4.  */
  5. function YOURTHEME_preprocess_html(&$variables) {
  6. foreach($variables['user']->roles as $role){
  7. $variables['classes_array'][] = 'role-' . drupal_html_class($role);
  8. }
  9. }