Attach a script to a particular node ID or view In Drupal 7, you can use the following code to attach a script to a particular content type:

function THEMENAME_preprocess_node(&amp;$variables) {
  if ($variables['type'] == 'INSERT_CONTENT_TYPE') {

        // include javascript
        drupal_add_js(path_to_theme() . 'INSERT_SCRIPT');

      }

    }


What code do you need to use to attach a script to a particular Node ID or a specific View?

I have tried swapping variables['type'] with various items, but none seem to work.
Node ID:

function THEMENAME_preprocess_node(&amp;$variables) {
  if ($variables['nid'] == 'INSERT_NODE_ID') {
    // include javascript
    drupal_add_js(path_to_theme() . 'INSERT_SCRIPT');
  }
}


View:

function THEMENAME_preprocess_views_view(&amp;$variables){
  if ($variables['name'] == 'INSERT_VIEW_MACHINE_NAME') {
    // include javascript
    drupal_add_js(path_to_theme() . 'INSERT_SCRIPT');
  }
}