I've added some javascript to drupal 6.0, and I'd like to know if I'm doing things the proper way.

What I've done:

1. added a *.js files to my custom theme folder.

2. in my custom page.tpl.php added the following line to the head:

<script type="text/javascript" src="http://mysite.net/sites/all/themes/mytheme/myscript.js"></script>

This seems to work, but I'm concerned about having an absolute link, as well as I'm not sure if this is the right place to be putting *.js files.

Comments

bjornarneson’s picture

This may be what you are looking for:

http://drupal.org/node/171205#scripts

-B

zilla’s picture

wow, never really got that...but putting in .info certainly make life easier...you just need to remember to update if you're updating theme and so on..

to do this, must one create a new folder within the theme called 'scripts' or something like that to manage the repository?

Anonymous’s picture

The easiest way without creating a module is in your template file adding:

drupal_add_js(drupal_get_path('theme','yourthemename') . "/scripts/script.js");

This will add it into , and will also aggregate with other JS files if you've got the appropriate caching turned on.

Joshua Boyd
joshua.d.boyd at gmail dot com

ardarvin’s picture

I wasn't able to get the:

scripts[] = myscript.js

line to work in the theme.info file, but the drupal_add_js(...) line in the template.php file did the trick.

The documentation is a little sparse in the scripting area of the Drupal 6 theming handbook.

ikati’s picture

I can't get this to work either. does the scripts[] statement not work in the .info file for the theme for drupal 6.x?

Lynne

yorch’s picture

In order to work, you need to "clear cached data" from site configuration/performance screen. Then it will read scripts[] statement from info file.

Yorch.

ikati’s picture

thanks.. I resolved this, and posted about it here:

http://drupal.org/node/266585

Lynne