Smarty:如何用php获得相同的结果

时间:2011-07-25 00:54:15

标签: php mysql database smarty

示例:URL包含在smarty变量

{$image->url|escape:'htmlall':'UTF-8'} 

这是图像表中的url字段。好的,现在在php中有以下内容:

echo "<![CDATA[<img src='...' alt='thumb' />";

如何将内容替换为img src以获取包含在smarty变量中的数据库中的url?

修改: 我必须像smarty那样从图像表中的数据库中读取URL字段,结果文件是.php,它显示带有xml格式的RSS

echo "\t\t<item>\n";
echo "\t\t\t<title><![CDATA[".$product['name']." - ".html_entity_decode(Tools::displayPrice(Product::getPriceStatic($product['id_product']), $currency), ENT_COMPAT, 'UTF-8')." ]]></title>\n";
echo "\t\t\t<pubDate>" . $logged . "</pubDate>\n" ;

之后我需要 IMAGE

1 个答案:

答案 0 :(得分:0)

就像是:

假设你的php代码是这样的:

define('_PS_BASE_URL_', 'something');
define('__PS_BASE_URI__', 'something else');
$smarty->assign('image', $image);

tpl文件可能是 ,如下所示:

<![CDATA[<img src='{Smarty.const._PS_BASE_URL_}{Smarty.const.__PS_BASE_URI__}img/p/{$image.0.id_product}-{$image.0.id_image}-small.jpg' title='{$product.name}' alt='thumb' />

阅读常量here。同样,对于名称替换,您需要使用一些modifierfunctions

编辑2:

您可以使用this modifier替换文字

编辑3:

在php中的

只做:

echo "<img src='" , htmlentities($image->url, ENT_COMPAT, 'utf-8') ,  "' />";