I'd like to add some jQuery (for search highlighting) to my Drupal 7 Views with exposed search terms filter. The point is that when a user clicks a search terms (or terms) the jQuery then highlights those words they searched for in the returned results.

I created the following preprocess function in my template.php file:

    // add jquery.highlight-5.js just to the search views page
    function themename_preprocess_node(&$variables) {
      if(arg(0) == 'node' && arg(1) == '8' && arg(3) == null) {
        drupal_add_js(drupal_get_path('theme', 'themename') . 

But as I put this together I realize I don't know what to put in arg(1) for my Drupal View. Anyone know how to find out the 'nodeid' of the Drupal View?

1 Answer 1


Use hook views pre render instead.

function themename_views_pre_render(&$view) {

   if ($view->name == 'view_name' && $view->current_display == 'block_1') {
    drupal_add_js(drupal_get_path('theme', 'themename') . '/js/jquery.highlight-5.js');
  • replace themename with your theme name
  • replace view_name with your view name
  • replace block_1 with your machine name

enter image description here


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.