Wednesday, July 13, 2011

Adding Theme Javascript file in Module hook_init()

drupal_add_js(path_to_theme() . '/scripts/popup-validations.js');

Note:
If you are in accessing this code from Admin panel, path_to_theme() function will automatically map the
Admin panel theme. Ex: Rootcandy.

If you want to link your custom theme name in sites/all/theme folder name then you need to do the below
code to achieve that.

Syntax:
$theme_path = drupal_get_path('theme', 'Your theme name');

Ex:
$theme_path = drupal_get_path('theme', 'gemswebsitetheme'); 

Output: 
sites/all/themes/gemswebsitetheme
 
Now we can easily concatenate our Javascript file path with the above path.

i.e.  $theme_js = $theme_path . "/scripts/json2.js"

No comments:

Post a Comment

Followers