Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path of Images inside a component in Joomla

I have this very simple problem re file paths, and yet I have been trying to solve the problem to no avail. Your help would be much appreciated. I'm new to Joomla and here is my problem.

I would like to show an image located in the images folder of my component.

Example Path:

/joomlabasedir/components/com_mycomponent/images/image1.png

How can I correctly set the path to this image, from inside a view of my component.

I've tried the following in my code:

<img src="./images/images1.png">

But when the page gets loaded, the src gets prefixed with the SEF formatted link of the page that is currently being displayed.

Example. While viewing a 'View' called event, instead of the image path pointing to : localhost/joomla/components/com_mycomponent/images/image1.png, it points to the SEF formatted link as show below,

localhost/joomla/index.php/component-alias/event/images/image1.png

which is obviously the wrong path and results to a 404 error.

I have also tried using JPATH_ROOT, JPATH_COMPONENT, and also failed since these paths are actually giving the filesystem path of the file, which is considered as local resource thus can't be loaded.

I hope someone can help me on this seemingly trivial problem that I failed solve.

Thank you!

like image 538
ultrajohn Avatar asked Mar 07 '11 08:03

ultrajohn


People also ask

How do I add an image to a Joomla component?

At the top left of the page click on "Upload". Then, you'll see Upload box. Click "Browse" to locate the image on your computer, then "Start Upload" to upload the file to the server.

What is an image path?

type: string, default: "" Specifies a list of directories in which to look for image files as specified by the image attribute or using the IMG element in HTML-like labels.


1 Answers

<img src="<?php echo JURI::root();?>components/com_mycomponent/images/images1.png">
like image 77
Gaurav Avatar answered Oct 12 '22 18:10

Gaurav