编辑:我的问题适用于 Drupal 6 和 7,尽管我的代码示例是 Drupal 6。人们提供的答案对于 Drupal 的两个版本都很有用。
我目前正在 Drupal 中为 Drupal 6 网站创建移动主题,并尝试通过以下方式删除所有不必要的核心和模块 JavaScript 和 csspreprocess_page
我的 template.php 文件中的函数。 css 文件已成功删除,但我似乎无法删除 JavaScript。这就是我所得到的。在此示例中,除了 ajax 脚本之外,所有内容均已成功删除。
知道我做错了什么吗?
<?php
function mytheme_preprocess_page(&$vars) {
//////// remove unneccesary drupal head files for mobile version
// CSS
$css = drupal_add_css();
// core
unset($css['all']['module']['modules/user/user.css']);
unset($css['all']['module']['modules/node/node.css']);
unset($css['all']['module']['modules/system/defaults.css']);
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/system-menus.css']);
// contributed -- automatically generate the path—— just easier this way
$rm[] = drupal_get_path('module','filefield').'/filefield.css';
$rm[] = drupal_get_path('module','flickr').'/flickr.css';
$rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css';
$rm[] = drupal_get_path('module','logintoboggan').'/logintoboggan.css';
$rm[] = drupal_get_path('module','fieldgroup').'/fieldgroup.css';
$rm[] = drupal_get_path('module','views').'/css/views.css';
$rm[] = drupal_get_path('module','content').'/theme/content-module.css';
// remove the contribs from the array
foreach ($rm as $key => $value) {
unset($css['all']['module'][$value]);
}
// JAVASCRIPT
$scripts = drupal_add_js();
unset($scripts['module']['sites/all/modules/ajax/ajax.js']);
unset($scripts['module']['sites/all/modules/ajax/jquery/jquery.a_form.packed.js']);
// recreate the tempalate variables
$vars['styles'] = drupal_get_css($css);
$vars['scripts'] = drupal_get_js('header', $scripts);
}
?>
ETA:这是脚本在标题中打印的方式:
<script type="text/javascript" src="/sites/all/modules/ajax/jquery/jquery.a_form.packed.js?P"></script>
<script type="text/javascript" src="/sites/all/modules/ajax/ajax.js?P"></script>
我找到了一个潜在地此类问题的更好解决方案。我尝试了 Kerri 的方法,因为 Matt V 说这对他有用,但如果我可以避免的话,我真的不想编辑 template.php,而且不管它在我的环境中不起作用。我的问题是几个 JS 文件在一个特定页面上抛出错误。我所做的只是编写一个非常简单的新模块,仅在所需的页面上运行。所以-我创建了一个基本的 .info 文件,下面是 .module 代码。对我来说就像一个魅力。只需将“mysite_mymodule”替换为您为模块命名的任何名称,并将“my-page-alias”替换为您想要实现的任何页面别名。
<?php
/**
* Implements hook_js_alter().
*/
function mysite_mymodule_js_alter(&$javascript) {
$alias = drupal_get_path_alias($_GET['q']);
if ($alias == "my-page-alias") {
/**
* documentation about what I did and why I did it...
*/
unset($javascript['sites/all/modules/dhtml_menu/dhtml_menu.js']);
unset($javascript['sites/all/modules/apachesolr_autocomplete/apachesolr_autocomplete.js']);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)