1

Since I moved all scripts form the header to the bottom of the page (in the template file of my theme) I have the problem that some scripts of contributed modules (chosen and device geolocation from smart ip) are added before the JQuery library. Using Jquery this leads to an error:

Undefined variable: jQuery

What can I do to get the right order and what could be the reason of the fact that the order is only wrong when the scripts are added at the bottom of the page and not in the header?

2
  • Realizing after I answered, the first question should be: how did you move all of the scripts? Did you just print $scripts in your footer? Jul 29, 2013 at 19:35
  • @ChrisRockwell Yes, this is, what I did.
    – user5950
    Jul 29, 2013 at 19:36

1 Answer 1

3

Modules, via drupal_add_js() can define the 'scope' and 'weight'. The 'scope' defaults to header, so unless you change this via drupal_add_js() in your template.php file, you can't move print $scripts from your header, or you'll have this problem with, likely, most contrib modules.

To change this, you could do something like this in yourtheme_preprocess_page($vars):

$js = drupal_add_js();
$newJs = array()
foreach ($js as $s) {
  $s['scope'] = 'footer';
  $newJs = $s;
}

drupal_add_js($newJs);
1
  • As long as everything is following Drupal best practices for Javascript, I don't recall ever having a problem moving my <?php print $scripts ?> to the end of the body, but before $page_bottom in html.tpl.php.
    – mpdonadio
    Jul 29, 2013 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.