<?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上阅读更多内容。
更新:
放置此功能的正确位置是在template.php
您的主题文件中。实际上,在您的情况下,您需要传递要排除的 css 文件名数组。
没有传递参数的调用drupal_add_css()
将提供$css
一组 CSS 文件,这些文件将附加到您的主题中。所以现在是入场的好时机!
如您所见,在第一个foreach
循环中,我们只是在$css
数组中查找传递数组中存在的文件名$exclude
,以删除样式。我们在第二个循环中为样式插入做同样的工作。最后,我们返回所有样式的主题表示,这些样式应该使用drupal_get_css()
函数附加到主题。(在你的情况下可能没有)
那么,在哪里调用这个函数呢?_phptemplate_variables()
您可以在D5 或YOUR_THEME_preprocess()
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);
}
我相信你知道如何排除他们所有;)