1

I am attempting to add css classes to the body depoendant on what the page contains.

I am using the following...

function myTheme_preprocess_html(&$vars){
    //code here
    //eg.
    $vars['classes_array'][] = 'a-new-class-for-a-node';
}

I cannot get this to fire or add anything to the page. It will not drupal_set_message, echo or more importantly add any classes to the body tag.

What am I doing wrong here please? I am using Drupal 6.

8
  • Which id the machine name of your theme? Did you clear the cache?
    – arrubiu
    Dec 5 '14 at 13:43
  • add keyword function before myTheme_preprocess_html(&$vars), ie function myTheme_preprocess_html(&$vars){...} Dec 5 '14 at 13:50
  • Thank you. I do already have function in the code. It is still not doing anything. I also have the name of my theme where it says myTheme_preprocess_html. Anything else I am missing out on here?
    – daktau
    Dec 5 '14 at 14:14
  • If you just added keyword function then you need to clear the cache Dec 5 '14 at 14:53
  • Thank you. I already always clear all caches when editing any code. Still nothing is happening. Can you suggest something that I can put in the function so that I know it is being called?
    – daktau
    Dec 5 '14 at 14:54
2

I might be terribly wrong here, but there appears to be no such hook for Drupal 6. If so, it will never fire.

See https://api.drupal.org/api/drupal/6/search/hook_preprocess_html.

Perhaps you're backporting a theme from D7?

3
  • I can also not find the preprocess html hook for Drupal 6. +1. So the correct hook to add classes to body be template_preprocess_page? Dec 6 '14 at 5:16
  • Thank you. I added some code to page.tpl.php to add the classes. I will investigate using template_preprocess_page.
    – daktau
    Dec 8 '14 at 20:25
  • J.Reynolds It seems so. @daktau As long as the code isn't anything beyond a simple if and print statements. Complex logic should go in hooks and theme functions, as you already know.
    – Plamen
    Dec 9 '14 at 15:41

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.