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

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

问题描述

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



问题是,无论什么主题,我总是发现,Drupal适用于我的HTML内容,我的CSS样式表和与所选主题相关的CSS。我也试过,没有成功,使用stylestripper模块(安装在sites / all / modules)。不管我做什么,CSS页面都附加了CSS样式表,完全破坏了我的布局。



实现这一点的正确方法是什么?为什么stylestripper根本不工作?有空白的主题吗?我已经尝试过基本,母亲,禅宗等,但是我总是看到额外的CSS样式表应用于我的页面。



这是令我疯狂的,Drupal被别人选择其灵活性。
提前谢谢。

解决方案

   / ** 
*帮助函数允许容易的CSS排除+包括
* /
函数_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;
}
返回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 (未经测试)的操作时:

 函数YOUR_THEME_preprocess(& $ vars ,$ hook){
//要排除的样式文件名。
$ css_exclude_list = array(
'lightbox.css',
'lightbox_lite.css',
);

//使用以前定义的帮助函数。
$ vars ['styles'] = _phptemplate_get_css($ css_exclude_list);
}

我相信你知道如何排除'em all;)


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.

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.

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.

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

Read more at drupal.org.

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!

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)

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天全站免登陆