如何用smarty php计算总数

时间:2010-04-06 07:51:19

标签: php smarty

我在结帐时有一个“折扣前”价格清单,我想在底部的新div中计算这些价格的总数..有什么想法吗?

我想要计算的内容:

{if $item.Product.formattedListPrice}
<div id="salg" title="Rabatt"></div>
{/if}
<div id="cart2Salg">
{if $item.Product.formattedListPrice}
    <span class="listPrice" title="Opprinnelige prisen">
    {$item.Product.formattedListPrice.$currency}
    </span>
    {else}
    <span class="listPrice">

    </span>

{/if}
</div>

我是如何计算的:

{foreach $item.Product.formattedListPrice.$currency as $savedtotal}
  <div  id="savedtotals"> {$savedtotal.formattedAmount.$currency}</div>
{/foreach}

感谢。

1 个答案:

答案 0 :(得分:3)

通常,您将为业务逻辑中的模板准备好所有数据。在极少数情况下,您可能希望执行与格式相关的样本计算,您可以使用Smarty的math function

对于您目前的情况,您可以使用:

{math equation="x * y" x=$savedtotal.formattedAmount y=$currency format="%.2f"}
相关问题