3

There are classes in the body like .front and .no-front that are good for styling front page separately and etc.

I am using same theme for front end and back end and would be nice if there was some .admin-end class in the body each time when editing content or just being in admin zone when logged in.

2

Depending on your theme, you should be able to do something like this:

function YOURTHEME_preprocess_html(&$variables) {
  global $user;

  if ($user->uid) {

    if (arg(0)=='admin') {
      $variables['classes_array'][] = 'admin-page';
    }
    if (arg(0)=='node' && arg(2)=='edit') {
      $variables['classes_array'][] = 'node-edit-page';
    }

  }

}
1

Jimajamma answer is correct and works. I configured it a bit.

function YOURTHEME_preprocess_html(&$vars) {
  global $user;
  if ($user->roles) {
    foreach ($user->roles as $key => $value) {
      if ($value =='administrator') {
        //print "<h1>Logged in as admin</h1>";
        $vars['classes_array'][] = 'admin-page'; 
      }
    }
  }
}

This way all users with administrator authentication get same class added to body.

0

Drupal core actually already provides classes that should be enough.

In template_preprocess_html() it calls theme_get_suggestions() and adds a bunch of css classes based on the path.

So for any path you are on that starts with admin there will be a class page-admin.

For example the path admin/content would have the classes: page-admin page-admin-content

and admin/structure/views would have page-admin page-admin-structure page-admin-structure-views

and so on.

It is best not to add more classes if you can get away with using ones that are already there.

And for the node add pages you can use the page-node-add class and for the node edit pages you can use the class page-node--edit.

That last one is a little confusing but it is because the path is node/%/edit and so the class is page-node-%-edit but then % is stripped out because it is invalid for a class.

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.