amitgur
amitgur

Reputation: 462

View path inside default.php in joomla component

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

Answers (3)

Fury
Fury

Reputation: 4776

This will give you path to components/CURRENT COMPONENT.

echo JPATH_COMPONENT;

Source

Upvotes: 0

Craig
Craig

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

Praveen kalal
Praveen kalal

Reputation: 2129

You can try this

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

Upvotes: 0

Related Questions