Perform math in a Merge Template

Use Smarty tags to perform automatic math in a Merge Template.

Expand the functionality of a basic Merge Template by adding tags that allow the file to perform calculations based on the merged data. 

Simple math

You can include multiple tags within a single set of curly brackets to do various math operations. In a simple example, if you have two number fields on your form you can do the following:

  • Add: {$projectteam_0001|floatval+$projectteam_0002|floatval}
  • Subtract: {$projectteam_0001|floatval-$projectteam_0002|floatval}
  • Multiply: {$projectteam_0001*$projectteam_0002}
  • Divide: {$projectteam_0001/$projectteam_0002}

The result of any of the above calculations will be a single number in place of where you set the tag in your Merge Template. 

Assign variables

You can create new variables in your Merge Template by using merge tags. For example, continuing on the simple math example above, you can define a new variable called "field3" that is twice the sum of field 1 and field 2.

  • {assign var=field3 value=$projectteam_0001|floatval+$projectteam_0002|floatval}

Now that you have the new variable created, you can use it throughout your merge template.

  • {$field3} 

For more information on creating variables in your Merge Template file, visit the Smarty website.