How to reference a javascript file in a Joomla Component
I am writing two Joomla components during these few days. I got a problem, how to reference a javascript file in a Joomla Component. I used to do it in a cowboy way. I hard coded the path in the template! I should keep it inside the component!
I found the documentation, in the framework, that is a method calls AddScript. It will add a script in the header section. That is nice!
Code
<?php | |
$document = &JFactory::getDocument(); | |
$document->addScript( 'components/com_<component name>/script/jquery.js' ); | |
?> |
But please adding this in the component xml file:
Code
<files folder="site"> | |
........ | |
<folder>scripts</folder> | |
</files> |
It makes sure the script folder will be deployed.
Reference:
Joomla Documentation
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Feedback awaiting moderation
This post has 19 feedbacks awaiting moderation...
Form is loading...