Posted by jdln on December 22, 2012 at 4:22pm
I need to add a class of the user's role to my page. Ive tried the following but it doesn't work, and it seems from the comments its not working for others aswell.
function THEMENAME_preprocess_page(&$vars) {
if ($vars['user']) {
foreach($vars['user']->roles as $key => $role){
$vars['class'][] = 'role-' . drupal_html_class($role);
}
}
}
http://grasmash.com/article/drupal-add-current-users-role-body-classes
Comments
In Drupal 7, the body tag is
In Drupal 7, the body tag is output as part of html.tpl.php so you would want THEMENAME_preprocess_html() [Where THEMENAME is the actual theme name]
What's the actual code? Ive
What's the actual code? Ive tried a few variations of the following:
function THEMENAME_preprocess_html() {
if ($vars['user']) {
foreach($vars['user']->roles as $key => $role){
$vars['class'][] = 'role-' . drupal_html_class($role);
}
}
}
Thanks
jdln: Did you ever get this
jdln: Did you ever get this working?
Context Module
Actually, the context module will do this: http://drupal.org/node/1835530#comment-6869044