Under the Parameters section of the drupal_add_css() function, the documentation says this:

$path (optional) The path to the CSS file relative to the base_path(), e.g., /modules/devel/devel.css.

I believe this is incorrect; the CSS file should not include a preceding slash. The example should instead be

$path (optional) The path to the CSS file relative to the base_path(), e.g., modules/devel/devel.css.

In the drupal_get_css() function, one can see that base_path() is actually prepended onto the filename. I'm looking specifically at one of the lines that looks like this:

.= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n";

I spent a few hours today trying to find out why my calls to drupal_add_css() weren't working, only to track it down to this. Hopefully this can be fixed soon, if this is indeed a bug.

Thanks :)

#6 drupal_add_css-618280-D6.patch515 bytesdaniels220


valkire’s picture

jhodgdon’s picture

Version:6.9» 6.x-dev
Issue tags:-drupal_add_css, -drupal_get_css

Updating tags and version.

jhodgdon’s picture

Note that this is not an issue in Drupal 7.x.

Heine’s picture

Copied from #785314: drupal_add_css path documentation is incorrect, because it is not just the example that is wrong:

$path (optional) The path to the CSS file relative to the drupal root, e.g., modules/devel/devel.css.

jhodgdon’s picture

Issue tags:+Novice

Another good project for a novice doc contributor

daniels220’s picture

Status:Active» Needs review
new515 bytes

Patch attached. I didn't modify any of the language except fixing the /. That's important—everything else I'll leave to others to discuss.

jhodgdon’s picture

Status:Needs review» Reviewed & tested by the community

I don't understand Heine's comment in #4. base_path() is the same as the Drupal root, I think?

I think this patch is fine.

Gábor Hojtsy’s picture

Status:Reviewed & tested by the community» Fixed

Thanks, committed.

Status:Fixed» Closed (fixed)
Issue tags:-Novice

Automatically closed -- issue fixed for 2 weeks with no activity.