0

I need to add a class to the body based on the author of the user profile page. I have two roles on my site: standard and premium. I would like to create a body class to reflect this. So, if I am on a standard member's profile page (regardless of my role) "standard-member" would be added to the body classes. If I am on a premium member's profile page (again, regardless of my role) "premium-member" would be added to the body classes.

Is this something that can be done with the context module?

4

This can be achieved by using the template_preprocess_html function in the template.php file of your theme.

function yourtheme_preprocess_html(&$vars) {
  if (arg(0) == 'user' && is_numeric(arg(1))) {
    $user = user_load((int) arg(1));

    if (in_array('standard', $user->roles)) {
      $vars['classes_array'][] = 'standard-member';
    }

    if (in_array('premium', $user->roles)) {
      $vars['classes_array'][] = 'premium-member';
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.