Including JavaScript files from a theme
This recipe will list the steps required to include a JavaScript file from the .info
file of the theme. We will be using the file to ensure that it is being included by outputting the standard Hello World! string upon page load.
Getting ready
While the procedure is the same for all the themes, we will be using the Zen-based myzen
theme in this recipe.
How to do it...
The following steps are to be performed inside the myzen
theme folder at sites/all/themes/myzen
.
Browse into the
js
subfolder where JavaScript files are conventionally stored.Create a file named
hello.js
and open it in an editor.Add the following code:
alert("Hello World!!");
Save the file and exit the editor.
Browse back up to the
myzen
folder and openmyzen.info
in an editor.Include our new script using the following syntax:
scripts[] = js/hello.js
Save the file and exit the editor.
Rebuild the theme registry and if JavaScript optimization is enabled for the site, the cache will also need to...