Maneesh Mehta
Maneesh Mehta

Reputation: 507

image pathway in joomla module

I am creating a module in joomla 2.5 at here in default.php file i am using this code for calling a image

       <img src="/home_interior/templates/business13/images/img1.jpg" alt="" />

the image is store in this location

       wamp\www\home_interior\templates\business13\images 

but in front end image is not displaying,anyone help me.

Upvotes: 0

Views: 2157

Answers (3)

Lodder
Lodder

Reputation: 19733

You should use JURI::root() to define the root directory which will work for localhosts and online, like so:

<img src="<?php echo JURI::root(). 'templates/business13/images/img1.jpg' ; ?>" alt="Image 1" />

Note: you should also add text in the alt="" as it is required in HTML standards.

Upvotes: 0

Toretto
Toretto

Reputation: 4711

For this you can use JURI::root like this to show your image in the front end.

<img src="<?php echo JURI::root().'templates/business13/images/img1.jpg';?>" alt="" />

Upvotes: 0

Matteus Hemstr&#246;m
Matteus Hemstr&#246;m

Reputation: 3846

First of all, if you are creating a module it should be located at joomla_root/modules/mod_yourname/. If that is so, it seems strange to link to an image located in the template folder. The module should provide its own image, preferably located at joomla_root/media/mod_yourname/images/.

Now, to write that image element I recommend you to use JHTML::image.

public static function image (
    $file
    $alt
    $attribs=null
    $relative=false
    $path_only=false
)

Example:

<?php
echo JHTML::image('templates/business13/images/img1.jpg', 'Alt text');
?>

Upvotes: 3

Related Questions