big*_*ile 4 javascript drupal-views drupal-6
我想在视图中添加一个Jquery插件.但是,我不想通过.info文件添加,因为我不想在每个页面上添加它.我也不想将它添加到视图的标题或创建view.tpl.php文件.
此页面显示如何通过template.php将Java脚本添加到节点.反正有没有做类似的事情通过template.php文件将Java脚本添加到视图?
这是Daniel Wehner回答的一个例子.它假设您的视图称为"博客",您的显示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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3102 次 |
| 最近记录: |