I am trying to add my javascript to the section of the webpages on my drupal site.

I have followed the directions here... but no matter how I set it up.. it doesn't seem to put the link to the javascript on my webpages. I have cleared the cache (thru performance), and also cleared my browser cache before trying it each time.

here are the instructions:
http://drupal.org/node/171205

and here are the 2 ways I tried setting it up:

  1. try 1
    • add this statement into the .info file:
      scripts[] = mt.js
    • put the javascript mt.js into the /themes/garland/ folder
  2. try 2
    • add this statement into the .info file:
      scripts[] = /sites/all/themes/mt.js
    • put the javascript mt.js into the /sites/all/themes/ folder

neither one worked. what am I doing wrong?

Comments

ikati’s picture

is this the right way to specify the path? There were no examples in the writeup, so.. it makes it hard to tell. But.. I am assuming that when I start with "/", that the path is relative to the base of the drupal system, which is usually public_html

therefore:

scripts[] = /sites/all/themes/mt.js

would resolve to "http://www.mydomain.com/sites/all/themes/mt.js"

right?

Lynne

ikati’s picture

well, I gave up on adding the scripts statement to the info file.

so, I tried adding a drupal_add_js to my theme template. but... it still doesn't generate the call to my javascript. I am about to tear my hair out.. I've spent 3 days on this now.

I've got to be doing something wrong.. this should be a simple thing. but I cannot figure out what it is.

this is how I added the drupal_add_js:

I put my javascript : mt.js in my sites/themes/garland folder. the path to mt.js is:
/sites/all/themes/garland/js/mt.js

then I added this to the top of the template.php file for the garland theme:

<?php
drupal_add_js(drupal_get_path('theme', 'garland') .'/js/mt.js', 'theme');
?>

then I go to performance and clear cache.

then I create or edit a page where I call the javascript "mt.js".

nothing calling mt.js is generated in the header, and of course when I try to execute the javascript call, I get an error.

what am I doing wrong? I modded the CSS with no problem.. but trying to add javascript is making me tear my hair out.

can anyone help?

Lynne

ikati’s picture

bump.

just noticed I'm not the only person having trouble getting their own javascript into the section using the .info file

maybe there is a bug?

Lynne

suntog’s picture

Assuming you are using a subtheme, the .info file should already be in the /themes/your_subtheme directory. So you should specify a path from that directory. I placed my myscript.js into a directory called myscriptfolder. So my script[] path looks like this:

script[] = myscriptfolder/myscript.js

Then clear cache and see what happens. It worked for me.

mooffie’s picture

add this statement into the .info file:
scripts[] = mt.js
put the javascript mt.js into the /themes/garland/ folder
[...]
cleared the cache (thru performance),

It works for me, I've just tried this.

Tip: if you have a 'script.js' file in your theme folder it will be picked up automatically (provided you don't already have "scripts[] = ..." lines in your info files). You won't even have to clear the cache in this case.

Tip2: put alert('hi!') in your JS file to see if it get's loaded.

(Tip3: Drupal has a feature: it's enough to visit the theme settings page to cause the theme cache to get cleared.)

scripts[] = /sites/all/themes/mt.js

That won't work. Drupal adds the theme folder in front of what you type there, so you'll end up with '/themes/garland/sites/all/themes/mt.js', which doesn't exist. In other words, what you type there must be relative to the theme folder; it can't start with a '/'. The same rules apply to .css files, so there's nothing special here.

I have cleared the cache [...]
here are the 2 ways [...]
try 1 [...]
try 2 [...]
I've got to be doing something wrong..

Maybe you cleared the cache only in 'try 2'? Maybe you forgot to clear it in 'try 1'?

then I added this to the top of the template.php file for the garland theme:
[...]
drupal_add_js([...]

Works for me. I see 'gpdinoz' too reports success, in your other thread.

Add the following to your template.php,

drupal_set_message('you should see this message');

You should see this message. (No need to clear the cache here.) Perhaps you're not using Garland (or a theme that inherits it)?

ikati’s picture

It is like my cache is never really cleared. I swear.

I did this:
[code]add this statement into the .info file:
scripts[] = mt.js
put the javascript mt.js into the /themes/garland/ folder
[...]
cleared the cache (thru performance),[/code]

and.. there is no call to my javascript produced in the page. zip.

and i changed the fckconfig.js in my fckeditor module, and no matter what I do... that isn't picked up. i even changed the name to zfckconfig.js to see if it would bomb it with no fckconfig.js at all. didn't make any difference.. just worked the way it always did. like i did NOTHING.

I clear cache thru performance, and clear my browser cache. I logged in and out. I tried it with another browser... nothing.

it is like i have made no changes.

very frustrating.

I think i'm going to go to bed.

:(

Lynne

ikati’s picture

just wanted to say that the problems I was having had nothing to do with drupal. I had my site moved to another server, and I found out that when I was making these changes, my ftp program was pointint to my old server. so, I would see the changes on my server.. but when I would try them out by calling the url , it would go to the new server, and my change wouldn't be there.

Now.. everything works as it should. I put the scripts[] in the .info file, and it works great.

thanks for the help. i do appreciate it.

Lynne