Search code examples
templatesjoomla3.0script-tag

Where is the list of scripts to be loaded stored?


In a template, there are parts that call Joomla functions to load several javascript files, and others to load css files. The js files aren't hard-coded in the template files, AFAIK. Where does Joomla store this list of paths for Javascript files?


Edit


I'm looking for the source of the list used like this in the template:

$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$this->language = $doc->language;

$load_favthb = true;
$lscripts = $doc->_scripts;

foreach ($lscripts as $k => $v) {
  if (strpos($k, 'favth-bootstrap') !== false) { $load_favthb = false; break; }
}

Where is the source for $doc->_scripts stored?


Solution

  • If you're referring to javascript files loaded by your template (as opposed to say an extension on your site), then the paths to these files are typically in one of your template's files.

    There are all sorts of ways of building a Joomla template, and so these paths aren't specified in the same place in every template. But you'd always start by looking near the top of /templates/template-in-question/index.php

    As an example, you probably have the Beez3 template installed on your Joomla 3 site.

    Start by opening /templates/beez3/index.php, and if you work your way down from the top you'll find the Javascript files are loaded at lines 80-83
    javascript files loaded

    Instead of loading javascript files in index.php, some templates include them in a secondary file (often named 'params' or 'head' or 'includes') which is inserted into index.php.

    Either way, start by scanning down from the top of your template's index.php file

    Edit

    Where is the source for $doc->_scripts stored?

    Google <jdoc: include type=”head” /> if you want to know all the details, but most come from site-root/media/jui/ and site-root/media/system/

    If you were to edit one of these files directly, there's the chance that your edit could be overwritten with a Joomla update.

    A safer way would be to remove the js script you don't want, and then add a replacement.

    // remove unwanted script . Path is relative to site root
    unset($doc->_scripts[$this->baseurl.'/path/to/unwanted-script']);  
      
    // add your replacement script. Path is relative to template root
    $doc->addScript($tpath.'/js/new-script');