Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
brewern CreditAttribution: brewern commentedSubscribing
Comment #2
bibo CreditAttribution: bibo commentedsubscribe
Comment #3
RobLoachThat'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.
Comment #4
stackpr CreditAttribution: stackpr commentedThis 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):
Comment #5
ionmedia CreditAttribution: ionmedia commentedand what we can do with
jquery_ui_add(array("ui.dialog", "ui.progressbar", "ui.sortable"));
?Comment #6
kenorb CreditAttribution: kenorb commented#965680: jquery_update_preprocess_page() overwrite $variables['scripts']
#426764: Allow other modules to alter the replacements