views:

46

answers:

1

hi,

I want to remove a js file from my drupal website and add a custom one. This is the code I'm using in my template.php file, but it doesn't work (the old js file is still loaded). (I've cleared the cache)

function zen_preprocess_page(&$vars, $hook) {

/*update js file*/
$scripts = drupal_add_js();
unset($scripts['module']['sites/all/modules/lightbox2/js/lightbox.js']);
$scripts['module']['sites/all/themes/zen/zen/myjs/lightbox.js'] = array('preprocess' => 1, 'cache' => 1);
$variables['scripts'] = drupal_get_js('header', $scripts);

... thanks

+3  A: 

I tested your code, and it actually works, if you place it in hook_preprocess_page. Your problem is probably that you use the wrong proprocess function, so that it doesn't effect the $scripts variable you use in your page template, or that is it overridden somewhere later in the process.

Edit

  • You should not edit the Zen theme direct, but sub theme it instead.
  • Have you tried added the js file with drupal_add_js()?
  • Have you inspected the $variables['scripts'] after changing it to see if it was as expected?
googletorp
well, I'm using it at the end of zen_preprocess_page in my template.php file. Is that correct ? Indeed it partially works because the $scripts array is correctly updated but the old js file is still loaded instead of the new one.
Patrick
so yeah.. I'm updating the scripts variable, but my template page is still using the old one... should I refresh theme registry.. after that lines ?
Patrick
I saw you updated the question. This is what I'm saying.. the $variables['scripts'] is perfectly updated. But the variable $scripts in my theme page is not.
Patrick
@Patrick: Then you either don't pass the $variables var by reff, or the scripts variable you use in the page template is overridden somewhere else. Try naming it something else and use that in your page template. This should help you debug the problem.
googletorp
ok, i solved.. thanks. It was very stupid of me. The var $variables was supposed to be $vars instead.
Patrick

related questions