Reputation: 462
I'm building a component view in Joomla and I'm using a lot of JS in the file inside the component myview/tmpl/default.php.
Where is the best folder to store a separate JS file in a component and how to get a link to that file inside the default.php
Upvotes: 0
Views: 2218
Reputation: 4776
This will give you path to components/CURRENT COMPONENT.
echo JPATH_COMPONENT;
Upvotes: 0
Reputation: 9330
The recommended location for any web accessible media (images, javascript, css etc) required by a Joomla! Extension (component, module etc) is the /media
directory. This is covered in the Manifest documentation on the Joomla! docs website.
To put it simply, in your extensions directory include a directory called media
(or something meaningful to you). In that store all of your web accessible content, you can even have sub-directories like images
or js
or css
or all of them.
Then in your manifest XML add the media
element, like:
<media folder="media" destination="com_example">
<filename>logo.png</filename>
<folder>css</folder>
<folder>js</folder>
</media>
The Joomla installer will then create a folder for you inside /media
called com_example
, then you can access all your media files with calls like:
$document->addStyleSheet(JURI::root() . 'media/com_example/css/example.css');
$document->addScript(JURI::root() . 'media/com_example/css/example.js');
or
<img src="<?php echo JURI::root() . 'media/com_example/'; ?>logo.png"
Upvotes: 1
Reputation: 2129
You can try this
<?php echo JURI::root();?>components/com_mycomponent
Upvotes: 0