Menu

Conditional Statements

Updated: 2024-01-08

Conditional statements help you to show or hide content in a template using the data in a tax return file.

Basic Conditional Statements

The most basic conditional statement checks whether a field contains a value. 

  1. Copy a field code for the field you want to check.
  2. Paste the field code into the template and add a # (number sign) at the beginning of the field code to open the condition. For example {{# CurrentClient.Info.ID.Title }}
  3. Insert any content you want to display based on the condition.
  4. Paste the field code again and insert a / (forward slash) at the beginning of the field code to close the condition. For example {{/ CurrentClient.Info.ID.Title }} Alternatively, you can use the {{/ end}} to close a statement.

Anything content placed between the open and closing tags will appear or disappear based on whether there is data in the field.

Adding Logic

Conditional statements can become more powerful if you add logic to the field codes. You can do this using simple operators. For example:

  • Two field codes separated by and will check that both fields contain data.
  • Two field codes separated by or will check that either field contains data.
  • Operators like > (greater than), < (less than), = (equal to) and != (not equal to) allow you to compare the value in the field with another field in the tax return, or with a date or amount.

For example {{#T1Summary.CarryForward.M[1] > 0 or T1Summary.CarryForward.M[2] > 0 }} opens a condition that will display the content if either field has a value greater than zero. If both fields are zero, the content stays hidden.

When conditions get more complex, you can use parentheses to group statements together and compare them.

Whitespace and Formatting

As long as you keep the field code and the pairs of {{ }} double brackets together, it doesn't matter whether you add or remove the whitespace inside a statement.

For example, both these statements work

{{#CurrentClient.RRSPContributions.ClientRRSP.M[0]=0}}Test 1{{/end}}

{{ # CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0 }}Test 2{{ / end }}

However, this statement will not work

{ {# CurrentClient.RRSPContributions. ClientRRSP.M[0] = 0 } }Test 3{{ / end }}

The spaces between the {{ }} double brackets and within the field code break the statement.

Similarly, be careful how you apply formatting like italics, bold or font changes. Always select and format the entire field code. If you only format part of the code, it will not work.

Simplifying Code

To make it easier to read your code, you can split field codes into nested conditions that shorten the statements. For example:

  1. Wrap the entire section in a {{# CurrentClient}} {{/ CurrentClient}} and delete CurrentClient. from all the other field codes in the section.
  2. You can do the same thing with the form name, in this case {{# RRSPContributions }}.
Original Code

{{#CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0}}

This text will show only if there is nothing in the field.

{{/end}}

Simplified Code

{{#CurrentClient}}

{{#RRSPContributions}}

{{#ClientRRSP.M[0] = 0}}

This text will show only if there is nothing in the field.

{{/end}}

{{/RRSPContributions}}

{{/CurrentClient}}

Examples

Example 1: RRSP Contributions
  1. Open a T1 tax return and add an RRSP contribution.
  2. Open the Template Editor and create a new T1 template.
  3. Copy and paste the following code into a T1 template.

{{# CurrentClient.RRSPContributions.ClientRRSP.M[0] }}

You have contributed to your RRSP this year.

{{/ end }}

Preview the template in the Template Editor. The content will show if someone has an RRSP contribution. To test this condition, add and remove the RRSP contribution, then watch what happens in the preview.

Example 2: No RRSP Contributions

To add a section that displays when someone does not have an RRSP contribution, you can add arguments to the field codes to look for an amount in the field.

In the opening tag, add an = (equals sign) and the number 0 (zero) before the closing brackets, like this: {{# CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0 }}. Or copy and paste the following code:

{{# CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0 }}

You have not contributed to your RRSP this year.

{{/end}}

Example 3: RRSP Contributions Less Than $2000

Use the < (less than) symbol to test for an RRSP contribution less than $2000.

{{# CurrentClient}}

{{# RRSPContributions}}

{{# ClientRRSP.M[0] < 2000}}

This text shows if the RRSP contributions are less than $2000.

{{/ end}}

{{/ RRSPContributions}}

{{/ CurrentClient}}

Example 4: RRSP Contributions Greater than the RRSP Limit

Use the > (greater than) symbol and compare the contributions to the amount in the contribution limit field.

{{# CurrentClient}}

{{# RRSPContributions}}

{{# ClientRRSP.M[0] > PriorYearRRSPLimit.M[10]}}

This text will show only if the client's RRSP contributions more than their contribution limit for the year.

{{/ end}}

{{/ RRSPContributions}}

{{/ CurrentClient}}

Example 5: Signing Date

Use the rules in the Dates help topic to check when the return was signed.

{{# CurrentClient.Info.Filing.SigningDate = today() }}

The return was signed today.

{{/end}}

{{# CurrentClient.Info.Filing.SigningDate < today() }}

The return was signed {{ format(today() - CurrentClient.Info.Filing.SigningDate, "dd") }} days ago.

{{/end}}