我想在 View 中添加一个 Jquery 插件。但是,我不想通过 .info 文件添加,因为我不想在每个页面上添加它。我也不想将它添加到 View 的标题或创建 view.tpl.php 文件。
这page展示了如何通过 template.php 将 Java 脚本添加到节点。有没有办法通过 template.php 文件将 Java 脚本添加到 View ?
最佳答案
这是 Daniel Wehner 的回答示例。它假设您的 View 名为“博客”,您的显示 ID 为“page_1”。此代码进入 template.php。记得在向 template.php 添加新功能后清除模板缓存。
/**
* Implements hook_preprocess_views_view().
*/
function THEMENAME_preprocess_views_view(&$vars) {
$view = $vars['view'];
// Load the blog.js javascript file when showing the Blog view's page display.
if ($view->name == 'blog' && $view->current_display == 'page_1') {
global $theme;
drupal_add_js(drupal_get_path('theme', $theme) . '/js/blog.js', 'theme', 'footer', FALSE, TRUE, FALSE);
}
}
关于javascript - Drupal 6 - 将 Javascript 添加到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5129189/