javascript - Drupal 6 - 将 Javascript 添加到 View

标签 javascript drupal-6 drupal-views

我想在 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/

相关文章:

google-analytics - 为什么我的谷歌电子商务不起作用?

Drupal 6 : Why use ! t() 中的标记?

javascript - 将js添加到drupal节点表单

drupal - 在 View 中显示节点,但禁用节点页面

Drupal View 问题: Displaying results in two columns?

drupal - 我想在 Drupal 7 中的单个自定义页面中放置 2 个表单

javascript - Handlebars - 错误 : each doesn't match else

javascript - 在 node.js 中异步读取多个文件

javascript - 如何在透明png下方移动较低的z级元素

javascript - 使用 PDF-LIB 在 React 中渲染 PDF