Actions

API16

JHtml/image

From Joomla! Documentation

< API16:JHtml
Revision as of 17:45, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Write a element

[Edit Descripton]

Description:JHtml/image

Syntax

static image($url, $alt, $attribs=null, $relative=false, $path_only=false)
Parameter Name Default Value Description
$url The relative or absolute URL to use for the src attribute
$alt The target attribute to use
$attribs null An associative array of attributes to add
$relative false If set to true, it tries to find an override for the file in the template
$path_only false

Defined in

libraries/joomla/html/html.php

Importing

jimport( 'joomla.html.html' );

Source Body

public static function image($url, $alt, $attribs = null, $relative = false, $path_only = false)
{
        if (is_array($attribs)) {
                $attribs = JArrayHelper::toString($attribs);
        }
 
        if($relative)
        {
                $app = JFactory::getApplication();
                $cur_template = $app->getTemplate();
                if (file_exists(JPATH_THEMES .'/'. $cur_template .'/images/'. $url)) {
                        $url = JURI::base(true).'/templates/'. $cur_template .'/images/'. $url;
                } else {
                        list($extension, $url) = explode('/', $url, 2);
                        if (strpos($url, '/')) {
                                // Try to deal with plugins group
                                list($element, $url) = explode('/', $url, 2);
                                if (file_exists(JPATH_ROOT .'/media/'.$extension.'/'.$element.'/images/'.$url)) {
                                        $url = JURI::root(true).'/media/'.$extension.'/'.$element.'/images/'.$url;
                                } else {
                                        $url = JURI::root(true).'/media/'.$extension.'/images/'.$element.'/'.$url;
                                }
                        }
                        else {
                                $url = JURI::root(true).'/media/'.$extension.'/images/'.$url;
                        }
                }
                if($path_only)
                {
                        return $url;
                }
        } elseif (strpos($url, 'http') !== 0) {
                $url = JURI::root(true).'/'.$url;
        }
 
        return '<img src="'.$url.'" alt="'.$alt.'" '.$attribs.' />';
}

[Edit See Also] SeeAlso:JHtml/image

Examples

<CodeExamplesForm />