如何强制Drupal不使用CSS上的导入?

时间:2013-07-15 23:57:27

标签: drupal drupal-7 drupal-theming

我想使用脚本来重新加载我的CSS,但脚本使用标签,Drupal使用import来包含CSS(当不在开发站点上使用聚合时)。

我尝试使用hook_alter_css,但显然(使用dpm函数)不是导入的来源。 那么,我该如何覆盖这种行为呢? 谢谢!

2 个答案:

答案 0 :(得分:1)

这发生在关闭聚合​​时。如果您使用自定义主题,则可以解决此问题 在template.php文件中添加css文件时: -

drupal_add_css(path_to_subtheme() .'/layout.css', 'theme', 'all', $preprocesstheme);
$preprocesstheme set it to  false (true aggration is turned on).

使用此方法包含所有css文件。

答案 1 :(得分:0)

您还可以使用Link CSS模块来实现此目的。

或者,在您自己的自定义模块中,使用hook_css_alter,如下所述:http://e9p.net/disable-import-tags-stylesheets-while-development-drupal

/**
 *  Implements hook_css_alter().
 */ 
function mymodule_css_alter(&$css) {
  $preprocess_css = variable_get('preprocess_css', TRUE);
  if (!$preprocess_css) {
    // For each item, don't allow preprocessing to disable @import.
    foreach ($css as &$item) {
      if (file_exists($item['data'])) {
        $item['preprocess'] = FALSE;
      }
    }
  }
}