Question: Im writing a custom module that need to insert some javascript and css files only in a Views page.

Im using hook\_preprocess\_page, but I can not tell if the current page is from a view:

```
function mymodule_preprocess_page(&vars)
{
    var_dump($vars); //output: nothings that reference the views!
    if([view page])
    {
        drupal_add_js([...]);
        drupal_add_css([...]);
        // Rebuild scripts 
        $scripts = drupal_get_js();
        $vars['scripts'] = $scripts;
        // Same for css
    }
}

```

I know i could use a template file (page-my\_view\_page\_path.tpl.php), but the js and extra css must be included only if my module is enabled; **so I like to keep this things directly inside my module code**.

Ideas?

Answer: 
[`views_get_page_view()`](http://api.lullabot.com/views_get_page_view) finds out what, if any, page view is currently in use. If it returns NULL, then the current page is not a views' page.

But using `drupal_add_js()` and `drupal_add_css()` in a `hook_preprocess_page()` won't work as expected because the variable `$script` and `$style` variables have already been set by [`template_preprocess_page()`](http://api.drupal.org/api/drupal/includes--theme.inc/function/template_preprocess_page/6). Views's template preprocessing (see Jeremy French's answer) is probably a better place to add your CSS and JavaScript.
If you are adding JS or CSS to a specific callback then better to use [`hook_page_build()`](https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_page_build/7):