hi i'm trying to create a new drupal theme which has many different pages and many diffrent style pages and many css files. The template is for a specific website with specific modules and ofcourse each module has it own template i am developing my theme under zen. in template .info i had defined manay css files and my problem is: I WANT DRUPAL LOAD EACH .CSS FILE UNDER A SPECIFIC MODULE drupal has conditional stylesheet just for oher browsers[like IE6 IE7 , ...] but nothing for load in a specific module
+1
A:
You can write your own rules in template.php file of your theme. I'm often use this trick not for different modules, but for different paths.
if ($vars['is_front']) {
$vars['template_files'] = array();
if (file_exists(path_to_theme().'/page-front.tpl.php')){
$vars['template_files'][] = 'page-front';
}
if (file_exists(path_to_theme().'/style-front-ie6.css')) {
$vars['ie6_style'] .= "\n".'<link type="text/css" href="/'.path_to_theme().'/style-front-ie6.css" rel="stylesheet" />';
}
if (file_exists(path_to_theme().'/style-front-ie7.css')) {
$vars['ie7_style'] .= "\n".'<link type="text/css" href="/'.path_to_theme().'/style-front-ie7.css" rel="stylesheet" />';
}
if (file_exists(path_to_theme().'/style-front-ie8.css')) {
$vars['ie8_style'] .= "\n".'<link type="text/css" href="/'.path_to_theme().'/style-front-ie8.css" rel="stylesheet" />';
}
if (file_exists(path_to_theme().'/style-front.css')) {
drupal_add_css(path_to_theme().'/style-front.css', 'theme', 'all', FALSE);
}
} else {
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename .= '-'.$path_part;
$vars['template_files'][] = $template_filename;
if (file_exists(path_to_theme().'/style-'.$path_part.'-ie6.css')) {
$vars['ie6_style'] .= "\n".'<link type="text/css" href="/'.path_to_theme().'/style-'.$path_part.'-ie6.css" rel="stylesheet" />';
}
if (file_exists(path_to_theme().'/style-'.$path_part.'-ie7.css')) {
$vars['ie7_style'] .= "\n".'<link type="text/css" href="/'.path_to_theme().'/style-'.$path_part.'-ie7.css" rel="stylesheet" />';
}
if (file_exists(path_to_theme().'/style-'.$path_part.'-ie8.css')) {
$vars['ie8_style'] .= "\n".'<link type="text/css" href="/'.path_to_theme().'/style-'.$path_part.'-ie8.css" rel="stylesheet" />';
}
if (file_exists(path_to_theme().'/style-'.$path_part.'.css')) {
drupal_add_css(path_to_theme().'/style-'.$path_part.'.css', 'theme', 'all', FALSE);
}
}
}
}
}
$css = drupal_add_css();
$vars['css'] = $css;
$vars['styles'] = drupal_get_css($css);
Put this into template.php in phptemplate_preprocess_page function and now if you have a page with address http://example.com/catalog, you can use page-catalog.tpl.php and style-catalog.css for it.
Olexandr Skrypnyk
2010-10-16 12:55:43