Skip to content
  • There are no suggestions because the search field is empty.

Add an if statement to a Merge Template

Add an if statement to optionally show information based on field data in your Merge Template.

An "if" statement can be used with any field type, but it is most commonly used with field types that take a single choice between two or more options, such as checkboxes and picklists. You can output different information based on the choice by using "if", "elseif" and "else" statements.

"If" statements should also always be used in formulas that divide by a field. This avoids a "divide by zero" case, which causes your merge result to end in an error.

Checkbox example

By default, a checkbox merges as "Yes" when checked and "No" when unchecked. You can change this wording with an if statement.

For example, to show "Closed" instead of Yes and "Not yet completed" instead of No, use this tag:

  • {if $projectteam_0001 == 'Yes'}Closed{else}Not yet completed{/if}
Example Tag
Shown in multiple lines {if $projectteam_0001 == 'Yes'}
Closed
{else}
Not yet completed
{/if}
Shown in a single line {if $projectteam_0001 == 'Yes'}Closed{else}Not yet completed{/if}

Picklist example

A picklist field may have more than two possible answers. In that case, use a combination of if, elseif and else statements.

For example, if a picklist has three possible answers (Arch, Mech, Civ) and you want to spell each one out in your merged output, use this tag:

  • {if $projectteam_0001 == 'Arch'}Architectural information{elseif $projectteam_0001 == 'Mech'}Mechanical information{else}Civil information{/if}
Example Tag
Shown in multiple lines {if $projectteam_0001 == 'Arch'}
Architectural information
{elseif $projectteam_0001 == 'Mech'}
Mechanical information
{else}
Civil information
{/if}
Shown in a single line {if $projectteam_0001 == 'Arch'}Architectural information{elseif $projectteam_0001 == 'Mech'}Mechanical information{else}Civil information{/if}

Division formula example

When a formula divides by a field, the merge fails if that field is empty or zero. Wrap the formula in an if statement so the division only runs when the field you divide by is greater than zero.

For example, to show the repair cost per square foot from a currency field ($projectteam_0001) and a number field ($projectteam_0002), use this tag:

  • {if $projectteam_0002 > 0}{$projectteam_0001/$projectteam_0002}{else}N/A{/if}
Example Tag
Shown in multiple lines {if $projectteam_0002 > 0}
{$projectteam_0001/$projectteam_0002}
{else}
N/A
{/if}
Shown in a single line {if $projectteam_0002 > 0}{$projectteam_0001/$projectteam_0002}{else}N/A{/if}

To round the result to two decimal places, use the math function inside the if statement:

  • {if $projectteam_0002 > 0}{math equation="x / y" x=$projectteam_0001 y=$projectteam_0002 format="%.2f"}{else}N/A{/if}

If the number field is empty or zero, the merged output shows "N/A" instead of an error.

Read more about if/else statements on the Smarty website.