Drupal 6 - Add Javascript to View

I want to add a jQuery plugin to the view. However, I do not want to add the file via the .info, since I do not want it on every page. I also do not want to add it to the view title or create a view.tpl.php file.

This page shows how to add Java Script to Node via template.php. Is there a way to do something like adding Java Script to a view via a template.php file?

+4
source share
2 answers

Here is an example of Daniel Wehner's answer. It is assumed that your opinion is called "blog" and your display identifier is "page_1". This code goes into template.php. Remember to clear the template cache after adding new functions to 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 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); } } 
+5
source

You can use hook_preprocess_views_view

0
source

Source: https://habr.com/ru/post/1341462/


All Articles