API16:JHtml/image
From Joomla! Documentation
Description
Write a element
<! removed transcluded page call, red link never existed >
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.' />';
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples