I required to add a js file on a page which based on user id.

I put following code in mytheme_process_page function in template.php

 drupal_add_js(drupal_get_path('theme','mytheme') . '/js/utilities.js');

But the utilities.js file didn't show up in source even though a clear all cache

Comments

johnpitcairn’s picture

You mean mytheme_preprocess_page()? Drupal has already loaded the $scripts variable by the time processing gets to the _preprocess_page function. So you need to reload the variable to include your added js:

drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/utilities.js');
$vars['scripts'] = drupal_get_js();

Alternately, you could place your drupal_add_js() call in global code (outside any function) in your template.php, or (better) inside hook_init() in a simple custom module.

If "utilities.js" provides code that is not just for theme/template display, it should probably be in a module.

adrianmak’s picture

thanks for pointing out it's required to reload the script page variable