Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  Chris Rockwell Jul 29 '13 at 19:35
    
@ChrisRockwell Yes, this is, what I did. –  user5950 Jul 29 '13 at 19:36

1 Answer 1

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);
share|improve this answer
    
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. –  MPD Jul 29 '13 at 23:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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