I'm writing a .info file for a module, and I want to include a script which has been installed in /sites/all/libraries:

So I have included the line below in my .info file:

scripts[] = /sites/all/libraries/zeroclipboard-2.2.0/dist/ZeroClipboard.js

However, with or without the leading slash on this path, I always get the same result: Drupal treats this as relative to the module directory and tries and fails to load


So maybe I've answered my own question, but I can't find any definitive answer to this in the Drupal docs?

Thanks all,


  • BTW if anybody else is having the same issue, I've used hook_init() and drupal_add_js() to achieve what I needed: /** * Implements hook_init(). * Load the ZeroClipboard Javascript files at page load */ function clipboard_init() { drupal_add_js(libraries_get_path('zeroclipboard-2.2.0').'/dist/ZeroClipboard.js', array('group' => JS_LIBRARY, 'every_page' => TRUE)); } – Monkeybrain Aug 6 '15 at 11:53

_system_rebuild_module_data is responsible for that. There is a whole section in code just to make sure:

// Prefix stylesheets and scripts with module path.
$path = dirname($module->uri);
if (isset($module->info ['stylesheets'])) {
  $module->info ['stylesheets'] = _system_info_add_path($module->info ['stylesheets'], $path);
if (isset($module->info ['scripts'])) {
  $module->info ['scripts'] = _system_info_add_path($module->info ['scripts'], $path);

My guess is that module should never assume that something exists if module itself does not install it. It's a way to introduce errors. Also, allowing modules to reach outside their directory might be a security breach.

If you need a script you can't include in your module, use Libraries API. Of course there are other ways, but most of them is problematic, and fixing all problems would pretty much result in cloning this ready module anyway.

| improve this answer | |
  • @AddWebSolutionPvtLtd - don't do this! This code is quoted directly from Drupal source. It is taken from it letter by letter. Don't mess with it, that's simply stupid. If you disagree with Drupal's coding style, your choice, but you should never display this disagreement by code edits. Especially if code is quoted. – Mołot Aug 6 '15 at 13:26

If you are creating custom module then you can use these function to add library or js file from lirary.

$info = libraries_load('ui.tabs');
drupal_add_library('system', 'ui.tabs');
| improve this answer | |

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.