Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By bryank on
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
Whoops.. Apparently the code
Whoops..
Apparently the code got filtered
=-=
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.
Your styles are all passed
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);
How to unset CSS and add new CSS in Drupal 6
Since you are using Drupal 6, you can do it like this in template.php via the phptemplate_preprocess_page function:
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.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.