Drupal像css函数一样添加javascript(核心)

时间:2015-03-12 06:02:19

标签: drupal drupal-7

对于之前使用过Drupal编码的人来说,我的问题很简单,所以这并不包括我:)

我的问题是如何添加如下所示的函数来加载我的所有JS文件?

我正在使用最新的Drupal 7版

/**
 * 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));


}

2 个答案:

答案 0 :(得分:2)

你有drupal_add_css的模拟功能:

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

但是,如果您想在所有页面上使用JS(和CSS),则可以从主题信息文件中添加。

答案 1 :(得分:1)

是的,您还可以添加位于/sites/all/themes/your_sub_theme_folder/的YOUR_THEME.info文件中的 JS 文件,对于添加文件,它将是这样的:

; ========================================
; Scripts
; ========================================
scripts[] = js/your_file.js
相关问题