custom module add drupal_add_js and drupal_add_css

Categories

Component ID

1999856

Component name

custom module add drupal_add_js and drupal_add_css

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

Step 1) Create module info file "mythemescript.info" .

name = My theme Script
description = Developed by gajendra.
core = 7.x
engine = phptemplate

scripts[] = mythemescript.js
Using a preprocess_page function

To conditionally add js to the theme, you can use a process_page function:

Step 2) Create module file " mythemescript.module ".

function mythemescript_preprocess_page(&$vars, $hook) {
  if (true) {
    drupal_add_js(drupal_get_path('theme', 'mythemescript') . '/mythemescript.js');
    $vars['scripts'] = drupal_get_js(); // necessary in D7?
  }
}

Thanks:
Gajendra kumar Sharma