是否可以重写/覆盖自定义模板脚本变量中使用的默认 Drupal 7.26 jquery?
我的意思是其中一个 js 文件:
<script type="text/javascript" src="http://drupal.dev/misc/jquery.js?v=1.4.4"></script>
由自定义主题带来的?
我在 sites/all/MYTPL/template.php
中尝试过这个但它不起作用:
$scripts['misc/jquery.js']['data'] = $base_theme . '/js/packages/jquery-2.1.0.min.js';
我想知道是否有人在不使用任何模块(例如 jQuery Update
)的情况下管理它?
=== 已更新 ===
实际上,我在接受的答案的帮助下解决了这个问题,并根据@cojomojo 的答案进行了一些修改:
function THEMEname_js_alter(&$javascript) {
// Swap out jQuery to use an updated version of the library.
$javascript['misc/jquery.js']['data'] = drupal_get_path('theme', 'THEMEname') . '/js/packages/jquery-2.1.0.min.js';
}
最佳答案
在主题的 template.php
文件中使用此代码,在 hook_js_alter
中.
function [YOUR_THEME]_js_alter(&$js)
{
$jqKey = "my-new-jquery"; // a key for new jquery file entry
$js[$jqKey] = $js['misc/jquery.js']; // copy the default jquery settings, so you don't have to re-type them.
$js[$jqKey]['data'] = "https://code.jquery.com/jquery-2.1.0.min.js"; // the path for new jquery file.
$js[$jqKey]['version'] = '2.1.0'; // your jquery version.
unset($js['misc/jquery.js']); // delete drupal's default jquery file.
}
关于javascript - Drupal 7 在自定义主题中覆盖 jquery js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22900307/