Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
use full path to image with smarty {html_image} function

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
etcohen
Smarty n00b


Joined: 12 Aug 2008
Posts: 1

PostPosted: Tue Aug 12, 2008 2:37 pm    Post subject: use full path to image with smarty {html_image} function Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP