繁体   English   中英

在指定的变量中使用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}$");

问题是你没有声明/初始化金额变量值试试这个

$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}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM