如何摆脱 Drupal CSS 样式表?

发布于 2024-08-23 05:30:23 字数 391 浏览 7 评论 0原文

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

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

实现这一目标的正确方法是什么?为什么 styletripper 根本不起作用?有没有完全空白的主题可用?我尝试过 basic、mothership、zen 等,但我总是看到额外的 CSS 样式表应用于我的页面。

这让我抓狂,Drupal 因其灵活性而被其他人选择。 先感谢您。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦与时光遇 2024-08-30 05:30:24

如果您使用与核心文件匹配的文件名在主题的 .info 文件中定义 CSS 和/或 JavaScript 文件,则您将覆盖它们,如果您的覆盖不存在,则不会包含它们。

有关示例,请参阅 Tai 主题的 .info 文件

If you define CSS and/or JavaScript files in your theme's .info file using filenames that match the core files then you override them, and if your overrides don't exist then they're not included.

See the .info file for the Tao theme for an example

南汐寒笙箫 2024-08-30 05:30:24

我不认为这会起作用,但我认为只需删除主题的 page.tpl.php 中的以下行

 <?php echo $styles ?>

然后drupal将不会有任何自己的样式..
这可能适合你。


Nitz

I don't this will work but i think just remove the following line in your theme's page.tpl.php

 <?php echo $styles ?>

and then drupal will not any of its own styles..
this may be work for you.


Nitz

破晓 2024-08-30 05:30:23
<?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);
}

我确信您知道如何排除所有这些;)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文