I have a module which I have started to look to update to work in D6.

I am having trouble with the drupal_add_css function to add a piece of vital CSS to the page.

drupal_add_css() works perfectly when putting a css file in to it, but my css file needs some variables passed on to it.

In Drupal 5 this worked:

$main_css_path = drupal_get_path('module','fpss').'/'.$fpss_templatesfolder.'/'.$template.'/template_css.php?w='.$config->width.'&h='.$config->height.'&sw='.$config->sidebar_width.'';
drupal_add_css($main_css_path, 'module', 'all', FALSE);

This does not work in D6. If I take out all the variables including the ? it works, but as soon as the ? is added the CSS is no longer added to the page.

The template_css.php file acts as a CSS file through modifying the header:

header("Content-type: text/css; charset: UTF-8");

The only work around I can use is to use inline CSS which isn't preferable for performance.

Comments

jamestombs’s picture

bump

Tresler’s picture

Category: bug » support

Can you tell us what you are trying to do and what module it is for? I'm not going to say your approach is incorrect, not knowing the circumstances, but 9 times out of 10 you are better off using a theme function to alter the class or id of your output html and simply including all potential classes and ids in the single non-dynamic .css file. If that doesn't fit the circumstances, please provide us with some more info.

i.e. Do you really need to use php to alter the .css file?

I'm going to re-categorize this as a support request though, if you think otherwise, feel free to set back, but I'm thinking drupal_add_css() should only work with css files, not php files

-Sam

jamestombs’s picture

Status: Active » Closed (fixed)

It was originally for the Frontpage Slideshow module (http://drupal.org/project/fpss) which iSchool has now taken over and I have no control of, so I assume they are using a workaround.

The slideshow module used a third party script from JoomlaWorks which added it's CSS using a PHP file with CSS headers to use it properly, then the width and height of the slideshow are passed on to the PHP/CSS file. This could have been worked around by using inline CSS.

As I have no work with the module anymore, I will close this, if anyone wants to reopen it or create a new one feel free to do so.

trungonly’s picture

Status: Active » Closed (fixed)

Bump. I created a dynamic CSS content by creating a Drupal menu in the hook_menu like:

$items['my/css/dynamic.css'] = array(...);

And then trying to add this dynamic css:

drupal_add_css('my/css/dynamic.css');

the drupal_add_css doesn't seems to accept none-file parameter.

Any work around please?

trungonly’s picture

Status: Closed (fixed) » Active

Status: Closed (fixed) » Active

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.