Drupal 6 – Add css with drupal_add_js

I’ve used this method for years and I wanted to post a complete example as a reference.

I love the css_injector module but I like to keep my views’ css with my view.
So this code example has all my required elements for inserting css into a views php header;

  • CSS is readable during editing thanks to php’s HEREDOC
  • function are not re-declared
  • css is minified (Mostly, I keep the white space…)
  • the Drupal.behaviors syntax that ensures code is only ran on the page load
  • and it leverages drupal_add_js

Here it is with in-line comments: (more…)