<?php
/**
* Helper function to allow easy CSS excludes + includes
*/
function _phptemplate_get_css($exclude = array(), $include = array()){
$css = drupal_add_css();
foreach ($css['all']['module'] as $k => $path) {
$file = substr($k, strrpos($k, '/') + 1);
if (in_array($file, $exclude)){
unset($css['all']['module'][$k]);
}
}
foreach ($include as $file){
$css['all']['theme'][path_to_theme() .'/'. $file] = true;
}
return drupal_get_css($css);
?>
阅读更多内容drupal.org http://drupal.org/node/268943.
Update:
放置此函数的正确位置是template.php http://drupal.org/node/11811您的主题文件。实际上,在您的情况下,您需要传递要排除的 css 文件名数组。
致电给drupal_add_css() http://api.drupal.org/api/function/drupal_add_css如果没有传递任何参数,将提供$css
包含一系列将附加到您的主题的 CSS 文件。所以现在正是入手的好时机!
如你所见,在第一个foreach
循环我们只是寻找$css
传递中存在的文件名数组$exclude
数组,用于样式删除。我们在第二个循环中执行相同的工作以插入样式。最后,我们返回应附加到主题的所有样式的主题表示,使用drupal_get_css() http://api.drupal.org/api/function/drupal_get_css功能。(也许你的情况什么也没有)
那么,在哪里调用这个函数呢?您可以在中调用此辅助函数_phptemplate_variables() http://api.drupal.org/api/function/_phptemplate_variables/5对于 D5 或YOUR_THEME_preprocess() http://api.drupal.org/api/function/template_preprocess/6对于D6。正如我们在 D6 中看到的那样(未经测试):
function YOUR_THEME_preprocess(&$vars, $hook){
// Stylesheet filenames to be excluded.
$css_exclude_list = array(
'lightbox.css',
'lightbox_lite.css',
);
// Making use of previously defined helper function.
$vars['styles'] = _phptemplate_get_css($css_exclude_list);
}
我确信您知道如何排除所有这些;)