When I view my source, I have all these:

However, I have 3 stylesheets I want to include in the head.

How do I do this?

btw - this page is utilizing page-front.tpl.php

Thanks

Comments

bryank’s picture

Whoops..

Apparently the code got filtered

<link type="text/css" rel="stylesheet" media="all" href="Dev/modules/node/node.css?N" />
<link type="text/css" rel="stylesheet" media="all" href="Dev/modules/system/defaults.css?N" />
<link type="text/css" rel="stylesheet" media="all" href="Dev/modules/system/system.css?N" />
<link type="text/css" rel="stylesheet" media="all" href="Dev/modules/system/system-menus.css?N" />
<link type="text/css" rel="stylesheet" media="all" href="Dev/modules/user/user.css?N" />
<link type="text/css" rel="stylesheet" media="all" href="Dev/sites/all/themes/chacha/style.css?N" />
VM’s picture

api.drupal.org shows these two functions that have to do with calling css files in drupal 6.

http://api.drupal.org/api/function/drupal_add_css/6
http://api.drupal.org/api/function/drupal_get_css/6

Another way would be to just paste what you need to add, under the line that calls the css files in page.tpl.php though then you can aggregate them and I don't know off hand if they get cached with this method.

to compress the css files into one, you can use the css aggregator in administer -> performance
just remember to disable this feature when you are trying to work with the css or changes won't take effect. Reenable the css aggregator after the changes are made to recompile a compressed file.

gollyg’s picture

Your styles are all passed in to your template files as the $styles variable. To remove specific stylesheets you need to edit this variable.

This should be done within the template.php file, in a function called _phptemplate_variables (in Drupal 5 - something like that google it) or a preprocess hook in D6. This function is run before any processing of template files.

At this point you can modify your CSS by using a combination of drupal_add_css and drupal_get_css. This allows you to retrieve an array of css files currently registered and also to add new ones. If you need to remove a css file:

create a temporary array containing the current css
unset the array element for the css file you wish to remove
resest the css based upon that array

D5 sample code below:


$new_css = drupal_add_css();
// remove unnecessary CSS styles
unset($new_css['all']['module']['modules/user/user.css']);
// rebuild CSS
$vars['styles'] = drupal_get_css($new_css);

Jeff Burnz’s picture

Since you are using Drupal 6, you can do it like this in template.php via the phptemplate_preprocess_page function:

<?php
/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_page(&$vars) {

  // Unset stylesheets.
  $css = $vars['css'];
    unset($css['all']['module']['modules/node/node.css']);
    unset($css['all']['module']['modules/system/system-menus.css']);
    unset($css['all']['module']['modules/system/system.css']);
    unset($css['all']['module']['modules/system/defaults.css']);
    unset($css['all']['module']['sites/all/modules/cck/theme/content.css']);
    $vars['styles'] = drupal_get_css($css);  
}

You will need to clear the theme registry for this to work -> admin/settings/performance, "Clear cache data".

In Drupal 5 you could use a similar approach using _phptemplate_variables, though I haven't ever needed to do this so for D5 this remains untested.

To add new stylesheets (or simply over ride core stylesheets) you can include them in your themes .info file - http://drupal.org/node/171209.

This should be enough if you want to add your stylesheets to every page, otherwise you can do it via the API - http://drupal.org/node/225868

EDIT: I just wanted to add that unsetting system.css could break a lot of stuff in your drupal site, especially in the admin section and/or forms (think fieldsets, dragable widgets etc), I would think its better to simply over ride it in your .info file and modify it there.