我在template.php文件中有这段代码,理论上应将$header_scripts
数组中的脚本放入页面的<head>
,并将其他代码放在&#39中;页脚范围&#39;除非他们将自己的范围定义为标题。
它将脚本放在页脚中,但似乎并没有将我的modernizr放在任何地方。我已经检查了路径,这是正确的,所以它必须是别的东西,但我已经超出了Drupal的深度。
function lightweight_js_alter(&$javascript) {
// Collect the scripts we want in to remain in the header scope.
$header_scripts = array(
'sites/all/libraries/modernizr/modernizr.js',
);
// Change the default scope of all other scripts to footer.
// We assume if the script is scoped to header it was done so by default.
foreach ($javascript as $key => &$script) {
if ($script['scope'] == 'header' && !in_array($script['data'], $header_scripts)) {
$script['scope'] = 'footer';
}
}
}