My scripts don't seem to be loading?

<?php print $scripts ?> is in the page template header.
I've tried defining no scripts in the theme .info file - should I get a default set in this case (including jquery)?

I've also tried adding scripts[] = /misc/jquery.js into the theme .info file and still no scripts are getting rendered into the HTML.

Hopefully this is just a dumb error on my part and easily solved. Only 2 hrs sleep last night.
Thanks for any help in advance. P.

Comments

arh1’s picture

off the top of my head, make sure your theme also prints the $closure variable right before the end of the markup. something like:

  <?php print $closure; ?>

</body>
</html>
PED-1’s picture

Yes, it has the closure line. Hmm?

PE Design
http://www.pedesign.co.uk

christopherdoherty’s picture

I'm having the same issue and stumbled across this post. Were you able to resolve this and if so, how?

PED-1’s picture

Hi seedough, yes eventually resolved the issue by adding drupal_add_js() lines to my theme's template.php file.

e.g.
drupal_add_js(drupal_get_path('theme', 'yourthemename') .'/yourscript.js', 'theme');

Once I'd added this all the scripts loaded into the head properly. Very strange as the explanation doesn't suggest that you need to do this to get the scripts to load.

If this doesn't work let me know - I'm pretty sure it was just this.
Sorry should have posted back here soon as I resolved it. :-/ Bad me.

PE Design
http://www.pedesign.co.uk

bigknot33’s picture

I've never had to do this on other sites, but hey, it worked, and thanks.

Percept’s picture

I ran into the same problem ... first of all, make sure you added your JS files to the theme.info

; Scripts to include

scripts[] = js/yourjsfile-1.js
scripts[] = js/yourjsfile-2.js
...

AFTERWARDS make sure you clear your Drupal Cache ... after I cleared my cache it worked without having to use the add_js function like mentioned above.

tmsimont’s picture

I had the same problem... It took me several hours to figure this one out.

It seems Drupal won't load any javascript onto the page if it thinks it doesn't have to.

That is, if it's not aware on page load of any modules or theme .info files calling script into the page then it won't load its default script files ( jquery and drupal.js )

On a fresh drupal install, I tried running a jquery script on a page, and jquery was not loaded, because by default garland does not have any scripts in its .info file. I had not yet installed any modules that would call drupal_add_js either.

I added a blank script to the garland .info file, and cleared the site cache. Then, drupal loaded the blank script, along with jquery and drupal.js ( even though i didn't mention these 2 default scripts in the info file, or do anything to include them.... )

weirrrdd....

vsawant’s picture

I had the same 'scripts not loading issue', and it turned out the .info file that was transferred (using sftp) to Linux from my windows workstation had carriage return ("Control M") control character in every line. The scripts (script1.js, script2.js) were both wrapped to the single line because of this.

scripts[] = script1.js ^M script2.js

On Linux, I then converted the .info file to unix format using the following command

dos2unix mytheme.info

After clearing cache in Drupal admin console for the site, problem went away.
Hope this will be helpful for those who may have the same issue.

kalanh’s picture

@tmsimont: I had this issue today with a new D6 site build. I have everything working fine on my WAMP server but after an FTP transfer, DB dump and everything to do with migration to Linux, my jquery.js was not being included unless I was logged in as admin. Following the documentation, I found this:

http://drupal.org/node/171213

When JavaScript is added to a page through Drupal, jQuery is automatically added to the page.

I had specified this in my info file:

scripts[] = scripts.js

And at the root of my theme was an empty file called script.js. Spot the difference? Eventually I did, although this seems at odds with the documentation:

http://drupal.org/node/171213

In Drupal 6 there is a default script file, named script.js that can be added to a theme without specifying it in the .info file. If that script is included in the theme it will be automatically added to all pages. In Drupal 7 all script files need to be specified.

I like the D7 way best!