Question

I'm looking forward to implement taxonomy terms based CSS styling; especially for the body tag which I want to add the current terms.

Here is what I have so far:

function _phptemplate_variables($hook, $vars = array()) {
  global $node;

  switch ($hook) {
    case 'page':
      // die ('test');
      $vars['body_class'] = '';
      if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
        $vars['body_class'] = 'theme' . arg(2);
      }
      if (arg(0) == 'node' && is_numeric(arg(1))) {
        $node = node_load(arg(1));

        if (is_array($node->taxonomy)) {
          foreach ($node->taxonomy as $term) {
            $vars['body_class'] .= 'theme'.$term->tid;
          }
        }
      }

      if (drupal_is_front_page()) {
        $vars['body_class'] .= ' front';
      }
      break;
  }

  return $vars; 
}

I think the code is OK, but it never get called (see my 'die' function); using simple phptemplate engine and minimal Drupal 6 install.

What obviousness am I missing here?

Was it helpful?

Solution

The reason it is not called is because hook_preprocess_variables is for Drupal 5: you should use hook template_preprocess_page in Drupal 6.

So if your theme is called "mytheme", the function would be best named "mytheme_preprocess_page" in your template.php.


Also, Drupal and the Taxonomy modules already generate many body classes, so you should check out what classes already exist because it may be that you don't need to preprocess the page at all (if all you want is to add a body class depending on taxonomy).

OTHER TIPS

Well, years ago we wrote this up http://openconcept.ca/blog/jmlane/taxonomy_specific_css

It would need to be updated I expect for Drupal 6 or 7 but the principals still apply.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top