Search code examples
drupaldrupal-7

Drupal add javascript (core) just like the css function


My question is straight forward, for anyone who has coded with Drupal before, so that does not include me clearly :)

My question is how can I add a function like the one below to load all my JS files?

i am using the latest Drupal 7 edition

/**
 * If the user is silly and enables netcast as the theme, manually add some stylesheets.
 */
function _netcast_preprocess_html(&$variables, $hook) {
  // Add netcast's stylesheets manually instead of via its .info file. We do not
  // want the stylesheets to be inherited from netcast since it becomes impossible
  // to re-order the stylesheets in the sub-theme.
  $directory = drupal_get_path('theme', 'netcast') . '/netcast-internals/css/';
  drupal_add_css($directory . 'bootstrap.min.css', array('group' => CSS_THEME, 'every_page' => TRUE));
  drupal_add_css($directory . 'style.css', array('group' => CSS_THEME, 'every_page' => TRUE));


}

Solution

  • You have analogue function to drupal_add_css:

    https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7

    But also, if you want JS (and CSS) on all pages you can add then from theme info file.