I'd like to ask people's opinions on the best way to include css into a module. An example might be event.module which includes is own css file using:
$output .= theme('stylesheet_import', drupal_get_path('module', 'event') .'/event.css','screen');
This is a good way to include the css, but if a user wants to change parts of it for their own theme they either have to include the changes in their style.css file or change the module version of the css file. The latter is not ideal as later on in an upgrade you would need to merge the new (module defined) css file and your css changes, and it is not theme specific.
One method that I have used is to include the module css file as above, but also look in the theme dir for a css file and if it is there also include it (after the module version). So the code looks like:
global $theme;
if ($theme === NULL) {
$theme = init_theme();
}
$output .= theme('stylesheet_import', drupal_get_path('module', 'gallery') .' drupal_g2.css','screen') ."\n";
$themecss = path_to_theme() .'/drupal_g2.css';
if (file_exists($themecss))
$output .= theme('stylesheet_import', $themecss,'screen') . "\n";
}
There is a kludge here in that sometimes the $theme
variable is not initialised yet and so path_to_theme()
returns nothing, so I have to call init_theme()
.