Be careful what files you add code to. Editing core files, such as index.php in the templates folder, may not be the best solution. What if the template update? The file will be overridden. So just think about it.
Before adding a script, it is advisable to get the name of the current template:
$app = JFactory::getApplication();
$template = $app->getTemplate();
You .jscan use the following tags to import a file <head>:
$doc = JFactory::getDocument(); //only include if not already included
$doc->addScript(JUri::root() . 'templates/' . $template . '/file.js');
or you can add Javascript there, and then like this:
$doc = JFactory::getDocument();
$js = "
//javascript goes here
";
$doc->addScriptDeclaration($js);
Hope this helps
source
share