From Joomla! Documentation

< API15:JHTMLImage

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Checks to see if an image exists in the current templates image directory if it does it loads this image. Otherwise the default image is loaded. Also can be used in conjunction with the menulist param to create the chosen image load the default or use no image

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >


site($file, $folder='/images/M_images/', $altFile=NULL, $altFolder='/images/M_images/', $alt=NULL, $attribs=null, $asTag=1)
Parameter Name Default Value Description
$file The file name, eg foobar.png
$folder '/images/M_images/' The path to the image
$altFile NULL empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder
$altFolder '/images/M_images/' Another path. Only used for the contact us form based on the value of the imagelist parm
$alt NULL Alt text
$attribs null An associative array of attributes to add
$asTag 1 True (default) to display full tag, false to return just the path

Defined in



jimport( 'joomla.html.html.image' );

Source Body

function site( $file, $folder='/images/M_images/', $altFile=NULL, $altFolder='/images/M_images/', $alt=NULL, $attribs = null, $asTag = 1)
        static $paths;
        global $mainframe;

        if (!$paths) {
                $paths = array();

        if (is_array( $attribs )) {
                $attribs = JArrayHelper::toString( $attribs );

        $cur_template = $mainframe->getTemplate();

        if ( $altFile )
                // $param allows for an alternative file to be used
                $src = $altFolder . $altFile;
        else if ( $altFile == -1 )
                // Comes from an image list param field with 'Do not use' selected
                return '';
        } else {
                $path = JPATH_SITE .'/templates/'. $cur_template .'/images/'. $file;
                if (!isset( $paths[$path] ))
                        if ( file_exists( JPATH_SITE .'/templates/'. $cur_template .'/images/'. $file ) ) {
                                $paths[$path] = 'templates/'. $cur_template .'/images/'. $file;
                        } else {
                                // outputs only path to image
                                $paths[$path] = $folder . $file;
                $src = $paths[$path];

        if (substr($src, 0, 1 ) == "/") {
                $src = substr_replace($src, '', 0, 1);

        // Prepend the base path
        $src = JURI::base(true).'/'.$src;

        // outputs actual html <img> tag
        if ($asTag) {
                return '<img src="'. $src .'" alt="'. html_entity_decode( $alt ) .'" '.$attribs.' />';

        return $src;

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >


Code Examples