|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
etcohen Smarty n00b
Joined: 12 Aug 2008 Posts: 1
|
Posted: Tue Aug 12, 2008 2:37 pm Post subject: use full path to image with smarty {html_image} function |
|
|
open function.html_image.php from plugin directory.
note: height & width will be added to <img> tag
add this:
=======================
Code: |
case 'path':
if(!is_array($_val)) {
$_key = smarty_function_escape_special_chars($_val);
} else {
$smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
if (empty($_key)) {
$smarty->trigger_error("html_img: missing 'path' parameter");
return;
}
if (is_file($_key)) {
//set image file link
$file = str_replace($_SERVER['DOCUMENT_ROOT'],"",$_key);
//get image height & width
list($width,$height)=getimagesize($_key);
//set params
$params['width'] = $width;
$params['height'] = $height;
}
else {
$smarty->trigger_error("html_image: unable to find '$_key'", E_USER_NOTICE);
}
break;
|
=======================
right after this lines (line 70):
=======================
Code: |
case 'alt':
if(!is_array($_val)) {
$_key = smarty_function_escape_special_chars($_val);
} else {
$smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
|
=======================
now you can use {html_image path='full_path_to_file'} in your template pages.
i found this very useful when checking if image file exist:
Code: |
$imgFile = "path_to_img";
if (is_file($imgFile)) {
//return full path to image
//no need to change to document root url
$smarty->assign( 'image', $imgFile);
}
|
then in smarty
Code: |
{if $image !=''}
{html_image path=$image}
{/if}
|
enjoy! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|