A couple of pointers when you’re getting into theming Drupal the correct way rather than just hacking around as is most fun.

I seem to hit troubles getting the aggregator feature of Drupal working, and often end up just slapping an external CSS link call in to the page template.

The proper way to do is a little long winded, but gives us the speed optimisations offered by the aggregator facility.¬†Instead of putting <link … /> in the page.tpl.php file, use the drupal_add_css() function in your template.php file.

The best place to put it is in a function called <themename>_preprocess_page().

And here’s an example of what that function can contain…

function mytheme_preprocess_page(&$vars) {
  //JA Inject theme styles and js
  $resetcss = drupal_get_path('theme', 'mytheme') . '/yui/build/reset-fonts-grids/reset-fonts-grids.css';
  $thickboxcss = 'misc/thickbox/thickbox.css';
  $thickboxjs = 'misc/thickbox/thickbox-compressed.js';

  drupal_add_css($resetcss, 'module', 'all', 1);
  drupal_add_css($thickboxcss, 'theme', 'all', 1);
  drupal_add_js($thickboxjs, 'theme', 'header');

  $css = drupal_add_css();
  $vars['styles'] = drupal_get_css($css);
  $vars['scripts'] = drupal_get_js();
}

Some other things to watch out for .. make sure the path you provide the aggregator is relative from root but not relative to root… I’m not helping much am I!
I mean this …
misc/thickbox/thickbox.css
as oppossed to this …
/misc/thickbox/thickbox.css

Also make sure the web server has access to the files .. correct permissions etc.
I found that even pointing the aggregator at symlinks instead of the actual files was causing a problem .. probably to do with permissions on the real files.

Anyways .. hope that helps!

References:
http://api.drupal.org/api/function/drupal_get_css/6
http://api.drupal.org/api/function/drupal_add_js/6

Categories: Drupal

Jonathan Adjei

Jon's expertise in web development is legendary and he overseas all technical aspects of our projects from development to hosting (all through the command line!) Jon is excited by the latest techniques and keeps the company on track by finding ways to adopt new practices into our workflow.