tags:

views:

187

answers:

1

I'm creating a website in Joomla and wondering if there is a way to load a specific script in a specific page using php....

e.g. i want to load a : <script src="sample.js"> in the about us page where it is going to be use

the reason why I wanted to do this is that instead of having them all load in head section even if it is not being use in the page makes page slower...

+1  A: 

Are you trying to do this in a content item or a component? If you're trying to do it in a component, this is the way to add a JavaScript file to the head portion for only that page:

$document =& JFactory::getDocument();
$document->addScript(JURI::base() . 'path/to/sample.js');

If you're trying to do this in a content item, you'll most likely need to find or build a content plugin to scan for a token that tells Joomla to run code like above. I did this on one of the sites I built a while back. I had it set so that a plugin would search for tags like {js sample.js} in content items, extract the file name, add the script to the document, then search and replace the tag out of the article.

jlleblanc
http://extensions.joomla.org has several plugins/modules to allow inclusion of scripts and advanced HTML/PHP.
DisgruntledGoat
trying to add it in a content item with a animated collapsible div e.g. http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm (Example 4)
kwek-kwek