Including a JavaScript file in your Joomla! template
One of the most basic aspects of using JavaScript with your Joomla! template is including it within the page. There are two ways to do this—within the<head>
element of your template, or within the<body>
element of your template (best placed just above the</body>
element). We'll make use of the method that uses the<head>
template. (The reasons to do so are covered in another recipe of this chapter.)
Getting ready
Open your template's index.php
template, located in your template's subdirectory within your Joomla! installation's templates
directory.
How to do it...
1. Locate the
<head>
element of your Joomla! template in theindex.php
file and insert a<script>
element that references the JavaScript file(s) that you wish to use:<!-- some HTML omitted for brevity --> <script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/rhuk_milkyway/js/javascript-file.js"></script...