欢迎各位兄弟 发布技术文章
这里的技术是共享的
下面是drupal6移除或禁用css file的方法
function phptemplate_preprocess_page(&$vars)
{
$css = $vars['css'];
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
$vars['styles'] = drupal_get_css($css);
}
//下面是drupal6移除css和js的方法function phptemplate_preprocess_page(&$vars) {
vars['scripts'] = drupal_get_js();
//移除css
$css = drupal_add_css();//或者 $css = $vars['css'];
unset($css['all']['module']['modules/node/node.css']);
$vars['styles'] = drupal_get_css($css);
//移除js
$scripts = drupal_add_js();
unset($scripts['module']['sites/all/modules/...module-name/...path-to-js.../file-name.js']);
$vars['scripts'] = drupal_get_js('header', $scripts);
//$ return $vars;
}
//来自 https://drupal.org/node/897882
I need to remove all of the default css stylesheets drupal attaches to my theme. It's a pretty simple theme & site, and I don't want to bloat it with 1400+ lines of css that won't be used. One of the things that gets me with drupal theming is I spend half my time individually resetting drupal's default css instead of developing my own.
I noticed a topic around which involved a patch, that added the ability to remove default drupal stylesheets via the themes .info file - this was great until I realised that the css files were also removed in the admin theme (for which I am using Garland), making things pretty messy. I'd like to be able to individually remove the attached stylesheet elements for css files I don't want from the html (like system.css and default.css), to ease up the code and put a tiny little less strain on the server by opening up less connections - so removing instead of overriding is preffered.
So I'd like to do it through template.php - there are a few 5.x solutions which don't seem to work on 6.x
Anyone know of a decent way to remove the default css?
You can remove
<?php
print $styles
?>
I would be careful about removing styles, because you may end up breaking modules which use ajax/javascript and css.
-steve.
------------------------------------------------
http://www.designbrigade.com
------------------------------------------------
http://www.designbrigade.com
Howdy,
With drupal 6.x, you can use the theme.info file to overwrite the default system css files. For example, to over write the system menu default styling simply add:
stylesheets[all][] = system-menus.css
here is further explaination........
http://www.lullabot.com/blog/fixing-menu-css-themers-6
does not work!!! something is dynamicvally loading system.css straight from core :(
This does work (I've just used it). http://drupal.org/node/263967
Hydrant Ltd
www.hydrant.co.uk
I found another solution to control the default styles -
not to use the general default stylesheet files, but instead of it
to copy, change and redirect the default stylesheet files for my concrete new theme.
It can be done as follows:
1) copy defaults.css from modules/system to the folder of your theme
2) make the necessary changes in the new defaults.css in your theme folder
3) redirect the css file path in your new theme page.tpl.php file -
this means, that change the defaults.css file path in the variable $styles with PHP preg_replace function
For example if the new theme (including the new copied defaults.css) files are in the folder sites/all/themes/drupal-test-theme,
then replace in your page.tpl.php file the code
<?php
print $styles
?>
<?php
$styles = preg_replace('/modules\/system\/defaults.css/', 'sites/all/themes/drupal-test-theme/defaults.css', $styles);
print $styles;
?>
I can't believe this ignorance from Drupal developers. Obviously they are not web designers.
The more I learn Drupal the more disappointed I become. So much cycles are being wasted in this bloated system. What - can't turn off CSS one by one?
Solutions:
1. Kill $styles ? The sub process(es) are still firing off from the core. Wasteful and bloated. nd I loose the "what should be cool" functionality.
2. Preg match / RegX - anyone know what the CPU cost is on that? (apparently not, it is taxing and should not be used for what is NORMALLY a simple task)
3. Overload (term used cautiously) - well we know PHP is a junky language (HTML + ECMA at best). Overload is not possible in PHP, and Drupal actually creates a work around for that (good job on implementing a solid pattern). But you now have the bloated wasteful Java type scenario. This is also cycle wasteful.
I am looking for a solution, non of these are really doing it for me. My CSS is SO TIGHT Drupal can't handle it with out me gutting the hell out of the template system. I already use my own header class because the header control in Drupal can't do what I need to do everyday.
I agree with Ishus.
...Still looking for a solution to a SIMPLE problem...
edit - solution:
// conditional for admin styles
if(!user_access('administer')){
$styles=null;
}
This will wipe the styles unless admin.
http://drupal.org/node/155400 -> Documentation page for "Overriding the core and module stylesheets"
Adam A. Gregory
_____________________________
Drupal Developer and Consultant
http://adamagregory.com
In Drupal 7 add this function to your template.php file in order to remove certain default CSS files from HTML:
function THEME_css_alter(&$css) {
unset($css[drupal_get_path('module', 'system') . '/system.menus.css']);
unset($css[drupal_get_path('module', 'system') . '/system.theme.css']);
// unset($css[drupal_get_path('module', 'system') . '/system.messages.css']);
// unset($css[drupal_get_path('module', 'system') . '/system.base.css']);
// ...
}
$styles = preg_replace('//i', '', $styles);
来自 https://drupal.org/node/258756
Maybe this helps
I was trying to get the same thing done and for me this works, but I'm not sure if it is the correct way as I'm still new to Drupal:
in "template.php" I added the following function:
function phptemplate_preprocess_page(&$vars)
{
$css = $vars['css'];
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
$vars['styles'] = drupal_get_css($css);
}
I think after adding the function you need to go to /admin/build/themes so that Drupal recognises the function.
Log in or register to post comments