0

I've seen the answer here using the NID but I don't know this, I only have the URL. Is there is another way to do this please?

function MY_THEME_preprocess_node(&$vars) {
    if($vars['nid'] == 'XX'){
      drupal_add_js('path/to/js/file.js');
    }
}

1 Answer 1

1

Check out hook_views_pre_render https://api.drupal.org/api/views/views.api.php/function/hook_views_pre_render/7.x-3.x

That provides a view object where you could retrieve the machine name of your view and add your drupal_add_js when its the relevant view being loaded

1
  • Hi, thank you. I've include a function in the views.api.php file, but where do I find the result? (sorry have never done this before) I'm using: function THEMENAME_preprocess_views_view_unformatted($vars){ $view = $vars["view"]; $id = $view->id(); } Jul 20, 2020 at 7:05

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.