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 ;)
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.
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
来源:https://stackoverflow.com/questions/2340426/how-to-get-rid-of-drupal-css-stylesheets