不加载模块带的css文件

制作调试Dupal主题时经常会遇到系统模块自带的css文件带来的麻烦,最初的做法是从新定义相关的样式属性,后来看到Advanced Theme Construction Kit (ATCK)才长了见识,会发现原来可以这样。

来学习怎样不加载模块带的css文件

一、在主题的template.php中增加:

function atck_styles() {
  $css = drupal_add_css(path_to_theme() .'/page-layout.css', 'theme', 'all');
  $css = drupal_add_css();
  unset($css['all']['module']['modules/node/node.css']);
  unset($css['all']['module']['modules/system/defaults.css']);
  unset($css['all']['module']['modules/user/user.css']);
  return drupal_get_css($css);
}

注意:如果你使用该代码测试,请将function atck_styles()替换为function 你的主题名字_styles()
二、修改主题的page.tpl.php

将:<?php print $styles ?>替换为:<?php print 你的主题名字_styles() ?>

总结:

如果想不加载某个非drupal系统模块,如:tagadelic 模块,修改

function atck_styles() {
  $css = drupal_add_css(path_to_theme() .'/page-layout.css', 'theme', 'all');
  $css = drupal_add_css();
  unset($css['all']['module']['modules/node/node.css']);
  unset($css['all']['module']['modules/system/defaults.css']);
  unset($css['all']['module']['modules/user/user.css']);
  unset($css['all']['module']['sites/all/modules/tagadelic/tagadelic.css']);
  return drupal_get_css($css);
}

其sites/all/modules/tagadelic/tagadelic.css的路径是相对于base_path()

另外有点不明白作者为什么使用$css = drupal_add_css(path_to_theme() .'/page-layout.css', 'theme', 'all');来增加css文件,而不使用.info文件。

相关参考:drupal_add_css drupal_get_css path_to_theme()

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <img> <em> <del> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <h6>
  • 自动断行和分段。
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.