在赋值变量中使用smarty变量


Use smarty variable in assigned variable

我在PHP中分配了一个变量,从数据库中获取数据,如下所示:

$smarty->assign("text",$result->text);
$smarty->assign("amount",250);
$result->text中的

Amount is {$amount}$

和在我的.tpl文件中,我使用变量:

{$text}

但结果告诉我:

Amount is {$amount}$

有什么问题?

我更新了这个问题

试一下,会成功的

$smarty->assign("amount",250);
$smarty->assign("text","Amount is {$amount}$");

问题是您没有声明/初始化amount变量值试试这个

$smarty->assign("amount",250);
$smarty->assign("text","Amount is {$amount}$");

在赋值变量中解析变量应使用eval函数:http://www.smarty.net/docs/en/language.function.eval.tpl id479259

对于这个问题,当我试图显示消息时我们应该使用eval:

{eval $text}