Conditionals (#if)
Use #if to show or hide part of your template depending on your data.
Basic structure
Section titled “Basic structure”{{#if <expression>}} ...shown only when the expression is true...{{#endif}}Every #if must be closed with #endif.
Checking whether a field has a value
Section titled “Checking whether a field has a value”The simplest test is whether a field has any value at all:
{{#if matter.reference}}Your reference is {{matter.reference}}.{{#endif}}#else and #elseif
Section titled “#else and #elseif”{{#if property.tenure = "Freehold"}} This is a freehold property.{{#elseif property.tenure = "Leasehold"}} This is a leasehold property.{{#else}} Tenure not specified.{{#endif}}If property.tenure is Leasehold, this outputs:
This is a leasehold property.Comparing values
Section titled “Comparing values”| Operator | Meaning | Example |
|---|---|---|
= | equal to | property.tenure = "Freehold" |
!= | not equal to | property.country != "Scotland" |
> | greater than | property.price > 500000 |
>= | greater than or equal to | property.price >= 500000 |
< | less than | property.price < 500000 |
<= | less than or equal to | property.price <= 500000 |
- Numbers compare numerically. Text values must be wrapped in double quotes, e.g.
"Freehold". - Dates must be in UTC ISO format, e.g.
"2025-01-31T00:00:00Z". Use$nowto compare against the current date and time.
Combining conditions
Section titled “Combining conditions”Use and, or, and not, with brackets ( ) to group:
{{#if property.price > 500000 and property.tenure = "Freehold"}} High-value freehold property.{{#endif}}{{#if not (property.country = "Scotland")}} Not in Scotland.{{#endif}}Evaluation order
Section titled “Evaluation order”When no brackets are present, operators are evaluated in this order (highest precedence first):
( )bracketsnot>>=<<=containsissubstringof=!=andor
Text search: contains and issubstringof
Section titled “Text search: contains and issubstringof”| Keyword | Meaning | Example |
|---|---|---|
contains | The left value is a comma-separated list that includes the right value | enquiry.tags contains "urgent" |
issubstringof | The left value appears somewhere inside the right value | "Ltd" issubstringof stakeholder.client.1.organisation |
Both ignore upper/lower case. (enquiry.tags here is an example custom field holding something like urgent,probate.)
What counts as true or false
Section titled “What counts as true or false”| Value | Result |
|---|---|
yes, true | true |
no, false | false |
| Empty / no value | false |
0 (zero) | true |
| Any other non-empty value | true |
List with at least 1 item (used with #foreach) | true |
Empty list (used with #foreach) | false |
The words yes, no, true, and false are not case-sensitive.
Asking a question at generation time: #question
Section titled “Asking a question at generation time: #question”#question prompts the user with a yes/no question when the template is generated and stores the answer in a variable you can test with #if:
{{#question $includeWill "Should we include an offer of a will?"}}{{#if $includeWill}} Did you also know that we can provide a will with your conveyancing...{{#endif}}See Composition for the full details, rules, and caveats.