Drupal 7在自定义主题中覆盖jquery js文件

2024-03-15

是否可以重写/覆盖自定义模板脚本变量中使用的默认 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 https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_js_alter/7.

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.
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Drupal 7在自定义主题中覆盖jquery js文件 的相关文章