How to add js file in module's info file
A very basic .info file for our new module:
; $Id$
name = my_example_module
description = "My Example Module"
core = 6.x
Add one more line to our basic .info file.
scripts[] = my_example_module1.js
scripts[] = my_example_module2.js
This line won't be used by Drupal, but will be used by our module:
function my_example_module_init() {
foreach ($info['scripts'] as $script) {
drupal_add_js($path . '/' . $script);
}
}
The above function should be return in the .module file (hook_init)
It will read the module's .info file and load any JavaScript files specified in the scripts[] directive and add to the site using drupal_add_js (hope know about drupal_add_js)
; $Id$
name = my_example_module
description = "My Example Module"
core = 6.x
Add one more line to our basic .info file.
scripts[] = my_example_module1.js
scripts[] = my_example_module2.js
function my_example_module_init() {
$path = drupal_get_path('module', 'my_example_module');
$info = drupal_parse_info_file($path . '/my_example_module.info');foreach ($info['scripts'] as $script) {
drupal_add_js($path . '/' . $script);
}
}
The above function should be return in the .module file
It will read the module's .info file and load any JavaScript files specified in the scripts[] directive and add to the site using drupal_add_js (hope know about drupal_add_js)
Comments