This recipe will list the steps required to include a JavaScript file from within the .info
file of the theme. To ensure that the JS file is being included, we will be adding some sample code that outputs the standard Hello World! string upon page load.
While the procedure is the same for all themes, we will be using the Zen-based myzen theme in this recipe. It is assumed that this theme is the site's default theme.
The following steps are to be performed inside the myzen theme folder at sites/all/themes/myzen:
1. Browse into the
js
subfolder where JavaScript files are conventionally stored.2. Create a file named
hello.js
and open it in an editor.3. Add the following code:
alert("Hello World!!");
4. Save the file and exit the editor.
5. Browse back up to the
myzen
folder and openmyzen.info
in an editor.6. Include our new script using the following syntax:
scripts[] = js/hello.js
7. Save the file and exit the editor.
8....