In mi PHP file I have: <?php define('APP_BASEDIR', dirname(__FILE__)); define('HTTP_SERVER', 'http://localhost'); define('DIR_IMAGES', 'imagen/logos/'); // echo "<img src='" . DIR_IMAGES . "logo.jpg' />"; this works but now I want to use Smarty template ?> But now I want to show my image using my Smarty template using my DIR_IMAGES variable. show.tpl.php ========= <table width="100%" border="1" cellspacing="0" bordercolor="#000066"> <tr> <td width="50"> echo "<img src='" . DIR_IMAGES . "logo.jpg' />"; <<--- Here is my problem. </td> </tr> </table> What is my mistake?? Thanks.
Your sending your images as "<img src='"/home/user/public_html/images/something.jpg"/> That not not going to work! It has to be "http://example.com/images/something.jpg" If your looking for hardlinking images in an automated fashion put in your whatever.php file. define('DIR_IMAGES',$_SERVER['HTTP_HOST'] . '/imagen/logos/'); $smarty->assign('DIR_IMAGES', DIR_IMAGES); PHP: Then in the whatever.tpl use <img src="{$DIR_IMAGE}something.jpg" /> HTML: Or better yet just use relative urls starting with / <img src="/imagen/someting.jpg" /> HTML:
$_SERVER['HTTP_HOST'] returns the value in Host: from the header of the current request. So if your site is http://example.com. $_SERVER['HTTP_HOST'] will be "http://example.com". So define('DIR_IMAGES',$_SERVER['HTTP_HOST'] . '/imagen/logos/'); = define('DIR_IMAGES','http://example.com' . '/imagen/logos/'); $_SERVER PHP.net Manual
This is all my program. conf.php ====== <?php define("APP_BASEDIR", dirname(__FILE__)); define('SMARTY_BASEFILE', APP_BASEDIR . '/lib/Smarty-2.6.14/Smarty.class.php'); define('ADODB_BASEFILE', APP_BASEDIR . '/lib/adodb-492/adodb.inc.php'); define('DIR_IMAGES', '/imagen/logos/'); ini_set('session.gc_maxlifetime','1800'); // 30 minutes ini_set('error_reporting', 'E_ALL'); require_once APP_BASEDIR . "/clases/util/Plantilla.class.php"; session_start(); ?> index.php ======= <?php require_once "./conf.php"; $tpl = new Plantilla(); $tpl->assign('DIR_IMAGES', DIR_IMAGES); $tpl->display('portada.tpl.php'); ?> portada.tpl ======== {include file="header.tpl.php"} <table width="100%" border="1" cellspacing="1"> <tr> <td colspan="2"><div align="center">MAIN MENU</div></td> </tr> <tr> <td width="50%"><a href="admin/proceso1.php">Process 1 </a></td> <td width="50%"> </td> </tr> <tr> <td width="50%"><a href="admin/proceso2.php">Process 2 </a></td> <td> </td> </tr> </table> {include file="footer.tpl.php"} header.tpl.php =========== <table width="100%" border="1" cellspacing="0" bordercolor="#000066"> <tr> <td width="50"> <img src="{$DIR_IMAGES}logo.jpg"/> </td> <td width="52%">Something</td> </tr> </table> proceso1.tpl.php ============= {include file="header.tpl.php"} <table width="100%" border="1" cellspacing="1"> <tr> <td colspan="2"><div align="center">PROCESS 1 </div></td> </tr> <tr> <td width="50%"> </td> <td width="50%"> </td> </tr> <tr> <td colspan="2"><div align="center"><a href="../index.php">Return</a></div></td> </tr> </table> {include file="footer.tpl.php"} Root ==== conf.php index.php \imagen\logos\logo.jpg \plantillas\templates\header.tpl.php \plantillas\templates\portada.tpl.php \plantillas\templates\footer.tpl.php \plantillas\templates\proceso1\proceso1.tpl.php \plantillas\templates\proceso2\proceso2.tpl.php But de image does not show.
You still haven't shown what I asked you 4 days ago, the generated source code. (When you go in your browser > view source..) You should also read the sticky in this forum and learn how to paste code correctly.
OOPSS!! I'm sorry.... this is the generated source code in IE, when run Index.php. <table width="100%" border="1" cellspacing="0" bordercolor="#000066"> <tr> <td width="50"> <img src="/imagen/logos/logo.jpg"/> </td> <td width="52%">Something</td> </tr> </table><table width="100%" border="1" cellspacing="1"> <tr> <td colspan="2"><div align="center">MAIN MENU</div></td> </tr> <tr> <td width="50%"><a href="admin/proceso1.php">Process 1 </a></td> <td width="50%"> </td> </tr> <tr> <td width="50%"><a href="admin/proceso2.php">Process 2 </a></td> <td> </td> </tr> </table> <table width="100%" border="1" cellspacing="0" bordercolor="#999999"> <tr> <td bordercolor="#333333"><p align="center">My business.com</p> <p align="center">2009</p></td> </tr> </table> PHP: ..... and...... this is the generated source code in IE, when I choose Proccess 1 option: <table width="100%" border="1" cellspacing="0" bordercolor="#000066"> <tr> <td width="50"> <img src="logo.jpg"/> </td> <td width="52%">Something</td> </tr> .... etc. PHP:
Hey, you can access the constants you defined in your scripts with this: {$smarty.const.DIR_IMAGES} You do not need to do $smarty->assign('DIR_IMAGES', DIR_IMAGES); Scroll down to $smarty.const here: http://www.smarty.net/manual/en/language.variables.smarty.php