Updated: 2022-01-26
Conditional statements help you to display or hide parts of a template based on whether the condition is met within the open tax return.
Of course, you need to understand how to open the Template Editor and test your code. Learn about these in the Template Editor topic. And, most conditions begin with a field code or constant. Please read the help topic on Field Codes before continuing.
For a list of hidden and useful codes that you cannot find on forms, see the Template Code help topic.
All conditions contain an opening and closing tag:
{{#CurrentClient.Info.ID.Title}}
{{/end}}
tag or a closing version of the opening declaration {{/CurrentClient.Info.ID.Title}}
, using a / (forward slash) instead of a # (number sign).{{#T1Summary.CarryForward.M[1] > 0 or T1Summary.CarryForward.M[2] > 0 }}
opens a condition that if either field has a value greater than zero, the content following will display. If both fields are zero, the content is hidden.{{# T1.Income.TotalIncome < 30000 and (Info.Residency.ProvinceDec31="Ontario" or Info.Residency.ProvinceCurrent = "Ontario") }}
You may be eligible for special benefits.{{/end}}
evaluates whether a taxpayer resides in Ontario, has an address in Ontario and has an income less than $30,000.This example shows you how to quickly test whether there is a number or value in the field.
{{CurrentClient.RRSPContributions.ClientRRSP.M[0]}}
{{ two opening braces: {{#CurrentClient.RRSPContributions.ClientRRSP.M[0]}}
{{/CurrentClient.RRSPContributions.ClientRRSP.M[0]}}
(Or, use the closing tag {{/end}}
to close the condition.)What about if you wanted to do the reverse? Only show text if someone has not contributed to an RRSP this year? You can add arguments to the condition to test the value in the field. In this case, we will show you how to test that the value in the field is zero.
{{#CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0}}
As long as you keep the field code and the pairs of {{ }}
double braces together, it doesn't matter whether you add or remove the whitespace inside a statement.
For example, these two work just as well.
{{#CurrentClient.RRSPContributions.ClientRRSP.M[0]=0}}
{{ # CurrentClient.RRSPContributions.ClientRRSP.M[0] = 0 }}
This will not work:
{ {# CurrentClient.RRSPContributions. ClientRRSP.M[0] = 0 } }
The spaces between the {{ }}
double braces and within the field code will break the statement.
If you are creating a section where all the conditions within that section address the same part of the tax return, you can declare parts of the conditions and have them apply to the whole segment. See also the section on "Breaking up field codes" in the Field Codes help topic.
For example, pull out {{# CurrentClient}}
and then add an {{/end}}
code to wrap around the whole segment, then remove CurrentClient from all statements.
{{# CurrentClient}}
and then add an {{/end}}
code to wrap around the whole segment, then remove CurrentClient from all statements.{{# RRSPContributions }}
.Operator | Description |
---|---|
and |
Tests that both statements are true. |
or | Tests that either statements are true. |
> (greater than) | Tests that the value of the first statement is larger than the value of the second statement. |
< (less than) | Tests that the value of the first statement is smaller than the value of the second statement. |
>= (greater than or equal to) | Tests that the value of the first statement is larger than or equal to the value of the second statement. |
<= (less than or equal to) | Tests that the value of the first statement is smaller than or equal to the value of the second statement. |
= (equal) | Tests that the statements produce identical results. |
!= (not equal) | Tests that the statements produce different results. |
not() |
Wrap a field or statement in not() to indicate that it is the opposite. This is particularly useful when when writing a condition for an empty field. For example, to show something when the transit number field on the T1DD is empty:
|
isblank() or isempty() |
Tests whether a field is blank. Especially useful when testing for the presence of a date in a field. For example, to check whether that there is no spouse date of death on the Info worksheet:
Combine this with the not() function to do the reverse, test whether the field has something in it. For example, to test that there is a spouse date of death on the Info worksheet: {{not(isblank(CurrentClient.Info.Filing.SpouseDateOfDeath))}} |
count() |
Counts the number of items. For example to count the number of dependants: count(CurrentClient.Dependant Use it in a condition to test whether there are any dependants (either full returns or just a Dep worksheet) in the file:
Show this text if there are dependants in a file.
|
Note: There is no "else" operator, you need to reverse the condition.
Note: There is no "else" operator, you need to reverse the condition.
What about if you want to show a section because someone has a contribution greater than or less than a certain amount, or another field on the return? (Note, this section will use the simplified code to better show how the statements.)
{{# CurrentClient.RRSPContributions.ClientRRSP.M[0] < 2000}}
{{#CurrentClient.RRSPContributions.ClientRRSP.M[0] > CurrentClient.RRSPContributions.PriorYearRRSPLimit.M[10]}}
Learn how to format and code that returns a date in the Field Codes help topic. You can find a list of date constants in the Dates help topic.
{{date(YYYY, MM, DD)}}
or {{date(2017, 02, 18)}}
{{ format(today() - CurrentClient.Info.Filing.SigningDate, "dd") }}
calculates how long ago the return was signed.{{date(Constants.CurrentTaxationYear+1, 06, 15)}}
You can also use parentheses to group statements together and compare them.
A good example is when you need to combine an income threshold with something like residency:
Creating conditions is fairly straightforward when you are evaluating a numerical value or comparing field codes, but it becomes more challenging when you need to figure out the value assigned to check boxes.
In particular when working with check boxes that can have one, multiple, or no possible answers, you will need to test that one of the boxes was checked.
For example, in Example E, above, you have to figure out that the check boxes have the values of AllYears, SomeYears and Properties. These values do not appear on screen because the text associated with the check box on the form is usually different than the value behind the scenes.
To display the value of a check box, add the the box to the Data Monitor:
Most check boxes in TaxCycle allow you to select only one from the list, like the principal residence question on T1 Schedule 3. These style of check boxes have a single name in the left side of the data monitor and different values associated with each box.
Other check boxes allow you to select all that apply to a question. Such as the questions in Part A of the T1135. Behind the scenes, these are different. Each box has a different name and value, so you need to add each box to the Data Monitor to see the value, rather than adding just one and switching between them.