1

I am trying to add JavaScript in footer with drupal_add_js(drupal_get_path('theme', 'mytheme') .'/js/libs/jquery-1.7.1.min.js', array('type' => 'file', 'scope' => 'footer'));, but for some reasons, it is not getting loaded.

What is wrong in my code?

3

Consider what's at the top of the html.tpl.php file...a call to <?php print $scripts; ?>.

This would logically mean that all scripts added by drupal_add_js() in the current page call have already been rendered down into the $scripts variable, and printed to the page.

Thus, when you call drupal_add_js() inside html.tpl.php, it's too late to add new scripts with drupal_add_js().

This sort of code should never really be inside a template file anyway to be honest, it should be inside a preprocess function inside your theme's template.php file.

On another note, it looks like you're trying to insert jQuery 1.7 into the current page. This may cause you all sorts of problems as Drupal already loads its own version of jQuery into the page...you'll probably get conflicts.

The better way would be to install the development version of the [jQuery update][1] module, which has the option to use jQuery 1.7 throughout the site. I don't know the current state of this; the last time I checked (a couple of months ago) there were still some core JS elements that break using 1.7.

You can find a bit more info here: How do I update jQuery to the latest version I can download?

  • Thanks Clive, this is useful. I was writing js_alter_hook() in template.php and was using Jquery.noConflict() before all ...But I see there are some issues there. Do you have any idea with Jquery.noConflict() function...so that both JS can work. – user269867 Jul 10 '12 at 13:14
  • Have a look at the module in @BetaRide's answer, from the looks of it you should be able to configure that to work on certain pages without ever having to deal with the noConflict() part yourself. – Clive Jul 10 '12 at 13:20
2

Another option to get the latest jQuery version is the jQuery Multi module.

  • That's genius, can't believe I haven't seen that one before. @user269867 if you only need v1.7 for one or a handful of pages, go with this module it'll save you a lot of time – Clive Jul 10 '12 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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