2014-03-01 65 views
1

我已經添加了此代碼到一個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應添加數字,而不是隻在頁面上顯示公式...

回答

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}

+0

我試過,但它出來'0.00'。我認爲問題出在'{assign var =「totalearnings」value = $ p + $ b + $ w}'因爲其他變量正在處理您的代碼... – user3344670

+0

其實我只是想通了。看起來你在加號和變量之間不能有空格。 – user3344670

+0

@ user3344670我已更新我的帖子,看它是否有效 –

相關問題