View path inside default.php in joomla component

948

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

257

Answer

Solution:

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 calledmedia (or something meaningful to you). In that store all of your web accessible content, you can even have sub-directories likeimages orjs orcss or all of them.

Then in your manifest XML add themedia 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 calledcom_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"
578

Answer

Solution:

You can try this

<?php echo JURI::root();?>components/com_mycomponent
990

Answer

Solution:

This will give you path to components/CURRENT COMPONENT.

echo JPATH_COMPONENT;

Source

People are also looking for solutions to the problem: php - "IPN Delivery Failed. HTTP error code 404: Not Found" error is showing if used codeigniter controller to listen IPN notification

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.