如何定义变量并在smarty中回显它们?

时间:2014-03-01 21:44:45

标签: php smarty

我已将此代码添加到Smarty模板文件中:

$totalearnings = {$pendingcommissions|replace:' USD':''|replace:'$':''} + {$balance|replace:' USD':''|replace:'$':''} + {$withdrawn|replace:' USD':''|replace:'$':''};
echo $totalearnings;

这就是它在页面上的显示方式:

$totalearnings = 0.00 + 1010.00 + 2000.00;
echo $totalearnings;

我需要更改以使此代码正常工作? $totalearnings应该添加数字,而不是仅仅在页面上显示等式...

1 个答案:

答案 0 :(得分:0)

使用{assign var="name" value="Bob"}

尝试此操作
{assign var="p" value=$pendingcommissions|replace:' USD':''|replace:'$':'' }

{assign var="b" value=$balance|replace:' USD':''|replace:'$':'' }

{assign var="w" value=$withdrawn|replace:' USD':''|replace:'$':'' }

{assign var="totalearnings" value=0}

{assign var="totalearnings" value=$totalearnings+$p+$b+$w}

{$totalearnings}

{assign}