I have a front-end component view that I need to include a .js file in the header of (header is being generated by Joomla, not hard-coded in default.php). The front-end component file is mysite.com/components/com_arrcard/views/tmpl/default.php; the javascript file is located at mysite.com/administrator/components/com_arrcard/js/CalendarPopup.js.
Here’s what I tried in my default.php:
$document =& JFactory::getDocument();
$popUrl = JURI::root(true).'/website/documents/ccv.html';
$popImage = JURI::root(true).'/website/documents/cv_card.jpg';
$popPhone = JURI::root(true).'/website/documents/phone.html';
$document->addScript( JURI::root(true).'/administrator/components/com_arrcard/js/CalendarPopup.js' );
The $popImage and $popPhone variables are getting set correctly, but the script is not being added – when I look at the rendered page source, CalendarPopup.js isn’t anywhere.
Can anyone help me out? What am I doing wrong here? I’ve also tried
$document->addScript('administrator/components/com_arrcard/js/CalendarPopup.js' );
That doesn’t work either. The addScript code does work when including the exact same file in a view in the administrator com_arrcard component. Is there some limitation on where addScript works?
Your code does look correct. Perhaps try another method below, the first line is to include JS while the other for CSS (just in case someone stumbles upon this in future looking for css include).
Ensure that you use the DS (directory separator) so that Joomla can fill in the correct / or \ depending on the OS the site is running on.
So in your case you would need this line of code: