Actions

API16

JHtmlImage/site

< API16:JHtmlImage

The "API16" 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.

Description

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 transcluded page call, red link never existed >

Syntax

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

Defined in

libraries/joomla/html/html/image.php

Importing

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

Source Body

public static function site($file, $folder = '/images/system/', $altFile = null, $altFolder = '/images/system/', $alt = null, $attribs = null, $asTag = true)
{
        static $paths;
        $app = &JFactory::getApplication();
 
        if (!$paths) {
                $paths = array();
        }
 
        if (is_array($attribs)) {
                $attribs = JArrayHelper::toString($attribs);
        }
 
        $cur_template = $app->getTemplate();
 
        // Strip HTML.
        $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8');
 
        if ($altFile) {
                $src = $altFolder . $altFile;
        }
        else if ($altFile == -1) {
                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, ENT_COMPAT, 'UTF-8') .'" '.$attribs.' />';
        }
 
        return $src;
}


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

Examples

Code Examples


Advertisement