I'm trying to load some theme javascript only to one view(multiple displays). I've tried to use the views preprocessor funciton, but maybe I'm doing it wrong:

function themename_preprocess_views_view__viewname__page(&$variables){
  this doesn't run on view page;

I've also tried it with the function name themename_views_view(). There's not much documentation on this.

2 Answers 2


This should work:

 * Implements template_preprocess_views_view().
function themename_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  if ($view->name == 'view_name') {
    // Standardize the output for rows.
    drupal_add_js(drupal_get_path('theme', 'themename') . '/js/js_name.min.js', array('scope' => 'footer'));

Place this in your template.php and clear cache

function THEME_NAME_preprocess_views_view(&$vars) {
  $view = $vars['view'];

  if($view->name == 'YOUR_VIEW_NAME' && $view->current_display == 'YOUR_DISPLAY') {

    global $theme_path;
    drupal_add_js($theme_path . '/js/myfile.js');
    //OR MAYBE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.