Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Exclude Loading of CSS Styles System Tables

Submitted by on October 11, 2010 – 2:47 pmNo Comment

Drupal has embedded style files which define view of the main page elements such as menu type, tabs and tables. If you don’t need these elements, you can redefine them line by line in CSS file but this can be a little bored.

The simpler way is don’t download these files.

We are talking about these two files:

  • /modules/system/defaults.css
  • /modules/system/system.css – it is full of deeply embedded selectors and can cause a headache  when adjusting your theme.

Before making changes
If you exclude these files, you should include another theme with style files for admin area.

After making changes
After adding the required functionality, you should open /admin/build/themes in browser to let Drupal view the function. Perhaps you will need to click Save button on the theme page…

Solutions
  • Delete CSS file in template.php (Drupal 5, 6)
  • Redefine system CSS-file in theme.info (Drupal 6 and higher)
  • Change paths to system CSS-files

Delete CSS file in template.php

Drupal 6

Add the following to template.php of current theme:

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

Drupal 5

Add the following to template.php of current theme:

function _phptemplate_variables($hook, $vars) {
$css = drupal_add_css();
unset($css[‘all’][‘module’][‘modules/system/system.css’]);
unset($css[‘all’][‘module’][‘modules/system/defaults.css’]);
$vars[‘styles’] = drupal_get_css($css);
return $vars;
}

If “_phptemplate_variables” function already exists in template.php then you should insert this code into the existing function.

Delete CSS-files of modules
here is the example of excluding CSS-file of Help module:

function _phptemplate_variables($hook, $vars) {
$css = drupal_add_css();
$rm = drupal_get_path(‘module’,’help’).’/help.css';
unset($css[‘all’][‘module’][$rm]);
$vars[‘styles’] = drupal_get_css($css);
return $vars;
}

drupal_get_path function is used to find a path to a module because it can be located in different places.

Redefine system CSS-file in theme.info

This alternative is for Drupal 6 or higher.

Please redefine the default system style file in .info-file of your theme. For example, to redefine the default system styles for menu, you should add:

stylesheets[all][] = system-menus.css

Change paths to system CSS-files

Another way to solve the problem – do not use the default style files but copy these files, modify them and change a path to the file.

  1. Copy defaults.css from modules/system to a folder of a current theme
  2. Make the required changes in new defaults.css within the folder of a current theme
  3. Change a path to css-file in page.tpl.php of a current theme. This means to change a path to  defaults.css file in $styles variable with the help of preg_replace PHP function.

For example, if files of a new theme (including just copied defaults.css) are in sites/all/themes/drupal-test-theme folder, you should replace this code in page.tpl.php :

print $styles

with this one:

$styles = preg_replace(‘/modules\/system\/defaults.css/’, ‘sites/all/themes/drupal-test-theme/defaults.css’, $styles);
print $styles;

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.