Skip to content

Conditionals (#if)

Use #if to show or hide part of your template depending on your data.

{{#if <expression>}}
...shown only when the expression is true...
{{#endif}}

Every #if must be closed with #endif.

The simplest test is whether a field has any value at all:

{{#if matter.reference}}Your reference is {{matter.reference}}.{{#endif}}
{{#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.
OperatorMeaningExample
=equal toproperty.tenure = "Freehold"
!=not equal toproperty.country != "Scotland"
>greater thanproperty.price > 500000
>=greater than or equal toproperty.price >= 500000
<less thanproperty.price < 500000
<=less than or equal toproperty.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 $now to compare against the current date and time.

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}}

When no brackets are present, operators are evaluated in this order (highest precedence first):

  1. ( ) brackets
  2. not
  3. > >= < <= contains issubstringof
  4. = !=
  5. and
  6. or
KeywordMeaningExample
containsThe left value is a comma-separated list that includes the right valueenquiry.tags contains "urgent"
issubstringofThe 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.)

ValueResult
yes, truetrue
no, falsefalse
Empty / no valuefalse
0 (zero)true
Any other non-empty valuetrue
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.


← Data markers · Contents · Loops →