如何摆脱 Drupal CSS 样式表? [英] How to get rid of Drupal CSS stylesheets?

查看:21
本文介绍了如何摆脱 Drupal CSS 样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力完成以下任务.我需要使用 Drupal 6 作为项目要求,但我想将它与我自己的 HTML 和 CSS 样式表一起用于每个节点/视图/面板等.

I am trying to accomplish the following. I need to use Drupal 6 as a project requirement, but I want to use it with my own HTML and CSS stylesheets for each node/view/panel etc.

问题是,无论主题如何,我总是发现 Drupal 适用于我的 HTML 内容,包括我的 CSS 样式表和与所选主题相关的 CSS.我也尝试过使用stylestripper 模块(安装在sites/all/modules 中),但没有成功.无论我做什么,我的页面都会应用额外的 CSS 样式表,完全破坏我的布局.

The problem is, whatever the theme, I always found that Drupal applies to my HTML content both my CSS stylesheets and the CSS related to the theme chosen. I have also tried, without success, using the stylestripper module (installed in sites/all/modules). No matter what I do, additional CSS stylesheets are applied to my pages, completely destroying my layout.

实现这一目标的正确方法是什么?为什么stylestripper 根本不起作用?是否有完全空白的主题可用?我尝试过基本、母舰、禅等,但我总是看到额外的 CSS 样式表应用于我的页面.

What is the proper way to achieve this? Why stylestripper does not work at all? Is there a completely blank theme available? I have tried basic, mothership, zen etc, but I always see additional CSS stylesheets applied to my pages.

这让我发疯了,Drupal 被其他人选中是因为它的灵活性.提前致谢.

This is driving me crazy, Drupal was chosen by someone else for its flexibility. Thank you in advance.

推荐答案

<?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 上阅读更多内容.

Read more at drupal.org.

更新:
放置此函数的正确位置是在 template.php 文件中你的主题.实际上,在您的情况下,您需要传递要排除的 css 文件名数组.
调用 drupal_add_css() 没有传递参数,将为 $css 提供一组 CSS 文件,这些文件将附加到您的主题.所以现在是入场的好时机!

Update:
The proper place to put this function, is in the template.php file of your theme. Actually in your case you need to pass an array of css filenames which you want to exclude.
The call to drupal_add_css() with no arguments passed, will provide $css with an array of CSS files which are going to be attached to your theme. So this is the right time to get in!

如您所见,在第一个 foreach 循环中,我们只是在 $css 数组中查找存在于传递的 $exclude 中的文件名数组,用于样式删除.我们在样式插入的第二个循环中做同样的工作.最后,我们使用 drupal_get_css() 函数.(在你的情况下可能什么都没有)

As you see, In the first foreach loop we simply seek the $css array for filenames which are existed in the passed $exclude array, for style deletion. And we do the same job in the second loop for style insertion. And at the end of this, we return a themed representation of all styles that should be attached to the theme making use of drupal_get_css() function. (maybe nothing in your case)

嗯,在哪里调用这个函数?你可以在 _phptemplate_variables() 对于 D5 或 YOUR_THEME_preprocess() 对于 D6.正如我们在 D6 中看到的那样(未经测试):

Well, Where to call this function? You can call this helper function in _phptemplate_variables() for D5 or YOUR_THEME_preprocess() for D6. As we see this in action for D6 (untested):

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);
}

我相信你知道如何排除它们;)

I'm sure you know how to exclude 'em all ;)

这篇关于如何摆脱 Drupal CSS 样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆