Calculations

Here are some steps to take if you need to do some basic calculations within your document or other settings in WebMerge.  For example, you have created an order form, but you need to tack on an additional processing fee that is not calculated by your form.

Here are some examples of some basic calculations.  These simply print the result:

  • {($Variable1*$Variable2)|number_format:2}
  • {$Variable1+$Variable2}

If you need to save the values for later, you can use the assign function:

  • {$Variable3 = $Variable1+$Variable2}
  • {$Total = $Subtotal + $Shipping + $Tax}
  • {$Discount = ($Subtotal * 0.25)|number_format:2}
  • {$Percent = (100 * $Wins / $TotalGames)|number_format:2}

For more information on the mathematical calculations you can do within your documents, check out http://www.smarty.net/docs/en/language.math.tpl

Have more questions? Submit a request

2 Comments

  • Avatar
    Lee Kolm

    hi Jeremy, After looping through my table to show all the line items, i want to get a total at the bottom. I'm trying this, but i suspect there is a syntax error as i am only getting the last item in the array rather than the total. Help?
    Total Order Amount: {foreach from=$IODetails item=_iodetail}{assign var=SumSales value=$_iodetail.Revenue__c + SumSales }{/foreach} ${$SumSales}

  • Avatar
    Jeremy Clarke

    Hi Lee,

    Try this instead:

    {foreach from=$IODetails item=_iodetail}{$SumSales = $_iodetail.Revenue__c + $SumSales}{/foreach} ${$SumSales}

Please sign in to leave a comment.
Powered by Zendesk