I used to include javascript files inside .tpl files by adding

drupal_add_js(drupal_get_path('theme', 'mytheme') . '/myscript.js');
$scripts = drupal_get_js();

, before print $scripts; this stops jquery update from working.

Comments

brewern’s picture

Subscribing

bibo’s picture

subscribe

RobLoach’s picture

That's some ugly code you have there. Try adding the script in a small custom module's hook_init(), or earlier on in the rendering process, like in template.php or something.

stackpr’s picture

This module does not actually modify the scripts as you call drupal_add_js. Instead, it modifies a copy of the array before building the $script variable at the preprocess_page step (jquery_update_preprocess_page). Since it is modifying a copy of the array, an additional call to drupal_get_js() is unaware of the changes.

#3 is right about trying to push the code earlier in the execution so this module (and others) can operate on the script.

However, with a deadline looming, you might try a custom JS scope like this (very hack-ish):

drupal_add_js(drupal_get_path('theme', 'mytheme') . '/myscript.js', 'module', 'custom-template-scope');
$scripts .= drupal_get_js('custom-template-scope');
ionmedia’s picture

and what we can do with jquery_ui_add(array("ui.dialog", "ui.progressbar", "ui.sortable"));?

kenorb’s picture