I need to store my css files at a location outside Drupal's path (e.g. /srv/assets/css/my_site/general.css). I attempt to achieve this using drupal_add_css but the browser loads them from:

http://www.my-site.com/srv/assets/css/my_site/general.css which results of course in 404 error.

Any idea how to load those external (file system) CSS files from within a module? note: I am using Linux.

  • BTW, I think drupal_add_css requires that the name of the CSS file begin with the modules names. For example, the custom module would require, the CSS file named custom.css. Not sure about this though. – Parag Jul 4 '16 at 19:51
  • It does not @PMagunia :) – Clive Jul 4 '16 at 22:05

drupal_add_css() expects a path relative to the site root. As such, if you're going to use drupal_add_css() you need to add a path within webroot to access the file.

One way to that is to use a symlink. For example

ln -s /srv/assets/css/my_site/general.css sites/all/modules/my_module/css/general.css

As long as the file is readable by your web server, you can use drupal_add_css to reference your symlink path.

drupal_add_css(drupal_get_path('module', 'custom') . '/general/custom.css', array('type' => 'file'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.