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() {
     $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 (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)
drupal add js, drupal_add_js, Romel Drupal, How to add js file in module's info file, Romel drupal_add_js, Romel drupal add js

Comments

Popular posts from this blog

PHP - How to increase size of POST value in php

D8 KernelEvents constants

D8 - Attach file programmatically to a node