1

I'm trying to add some other classes to my body in order to identify some pages. I've tried adding some classes, but for some reason drupal is not displaying them in the body.

Below is my preprocess_html and the output of $vars['classes_array'] and the actual output in html.

As you can see, only the class I added is not being displayed.

function theme_preprocess_html(&$vars) {
    $vars['classes_array'][] = drupal_html_class('page-' . $vars['head_title_array']['title']);
}

// output
array(10) {
  [0]=>
  string(4) "html"
  [1]=>
  string(9) "not-front"
  [2]=>
  string(9) "logged-in"
  [3]=>
  string(11) "no-sidebars"
  [4]=>
  string(9) "page-node"
  [5]=>
  string(10) "page-node-"
  [6]=>
  string(12) "page-node-41"
  [7]=>
  string(14) "node-type-page"
  [8]=>
  string(7) "i18n-en"
  [9]=>
  string(10) "page-legal"
}

// page output
class="html not-front logged-in page-node page-node- page-node-41 node-type-page i18n-en context-legal omega-mediaqueries-processed admin-menu responsive-layout-normal"
4
  • For what I can see, it seems to be completely ignoring this code
    – woutr_be
    Feb 3, 2012 at 6:06
  • So apparently $attributes also contains the body classes, but they don't get changes via $vars['classes_array']
    – woutr_be
    Feb 3, 2012 at 7:14
  • Is your function actually running? Is your function really named theme_ or is theme_ replaced with your actual theme's name? Feb 3, 2012 at 12:55
  • Yes, it is running, I posted the output of a var_dump in the function ...
    – woutr_be
    Feb 3, 2012 at 14:47

1 Answer 1

2

I don't know how your html.tpl.php looks like, since that will effect it, but by default the interesting line looks like this:

<body class="<?php print $classes; ?>" <?php print $attributes;?>>

So what you want to alter is not $vars['classes_array'] but $vars['classes']. This might explain why

context-legal omega-mediaqueries-processed admin-menu responsive-layout-normal

is printed out, but not in the $vars['classes_array'] array.

1
  • Thanks, I temporarily changed it by combining $classes and $attributes in one variable. But I guess yours is a better way.
    – woutr_be
    Feb 4, 2012 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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