Drupal Pitfall: @import-ing CSS

November 4th, 2009 Posted in drupal | No Comments »

Pitfall:

/* local.css */
@import "menu-styles.css"
@import "foobarbaz.css"

This pitfall causes style breakage when enabling Drupal’s CSS aggregation/caching.

Symptom

Some parts of the page (e.g., the primary links menu) look completely different after enabling caching.

Cause

Drupal’s CSS caching aggregates all your theme’s and your modules’ CSS files into one file (to minimize HTTP requests). But it doesn’t look for @import statements in CSS when doing so.

Solution

Declare all your CSS files in your theme’s .info file:

# mytheme.info
stylesheets[all][] = menu-styles.css
stylesheets[all][] = foobarbaz.css

and remove your CSS @import statements. (And as always, rebuild the theme registry for the changes to take effect.)

Drupal Pitfalls

November 4th, 2009 Posted in drupal | No Comments »

Forgetting to put

<?php print $closure; ?>

in your theme’s page.tpl.php.

Forgetting the closure prevents modules like Google Analytics from being able to put JavaScript at the end of the page body. Without that JavaScript, not much analytics…izing gets done.

This is a fairly common mistake, in my experience as a Drupal maintenance programmer.