•••
 
Documentation   /   Reference: syntax   /   Logic statements
 
 

Logic statements

 

Logic statements are written in double square brackets. They work in templates and in most workflow directives, such as titles, descriptions, Hidden answers and email bodies.

Statement Purpose
[[IF]], [[ELSEIF]], [[ELSE]] Show text when a condition is met
[[NOT]] Show text when a condition isn't met
[[VAR]] Set a variable, and optionally save it
[[ALTER]] Add to, subtract from or replace a variable
[[CHANGE]] Transform text
[[DATE]] Format a date or calculate a new one
[[MATH]] Calculate and format numbers
[[MAP]] Translate a value into a label
[[INCLUDE]], [[INCLUDEIF]], [[INCLUDENOT]] Embed documents, templates, images, data and widgets
[[REPEAT]] Repeat text for each row of a list. See Repeating sections.
Layout statements Links, buttons, page breaks, signature blocks, anchors

IF, ELSEIF and ELSE

[[IF=variable_name]]Some text[[ENDIF]]
[[IF=variable_name(My test)]]Some text[[ENDIF]]
[[IF=variable_name(MATCH_TYPE My test)]]Some text[[ENDIF]]
[[IF=variable_name(MATCH_TYPE My test)]]Some text
[[ELSEIF=other_variable(MATCH_TYPE Other test)]]Some other text
[[ELSE]]Some more text
[[ENDIF]]
Form True when
[[IF=variable_name]] The variable has a value that isn't 0 or blank
[[IF=variable_name(My test)]] The value equals "My test" (ignoring case)
[[IF=variable_name(MATCH_TYPE My test)]] The value passes the match type, such as GREATER_THAN £500
  • The test value can contain variables: [[IF=price(GREATER_THAN {{budget}})]].
  • Each [[IF]] or [[ELSEIF]] tests one condition. AND and OR aren't supported. For AND, put an IF inside a NOT, or calculate a combined value first with a Hidden item or [[VAR]].
  • IFs can't be nested inside other IFs: the first [[ENDIF]] closes the statement.
  • To test for a blank value, use [[NOT=variable_name]], not IS_BLANK.

NOT

[[NOT=variable_name]]Some text[[ENDNOT]]
[[NOT=variable_name(My test)]]Some text[[ENDNOT]]
[[NOT=variable_name(MATCH_TYPE My test)]]Some text[[ENDNOT]]

Shows the text when the condition is not met. [[IF]] statements can go inside [[NOT]], but not the other way round.

VAR

Sets a variable to the text between the tags. The statement itself outputs nothing.

[[VAR=variable_name]]{value}[[ENDVAR]]
[[VAR=variable_name,save:true]]{value}[[ENDVAR]]
  • The value can contain variables and other statements, such as [[IF]] and [[MATH]].
  • With save:true, the value is saved in the document so Data Studio can report on it.
[[VAR=total_fee,save:true]][[MATH=decimals:2]]{{day_rate}} * {{days}}[[ENDMATH]][[ENDVAR]]
The total fee is £{{total_fee}}.

ALTER

Changes an existing variable.

[[ALTER=add:variable_name]]{value}[[ENDALTER]]
[[ALTER=remove:variable_name]]{value}[[ENDALTER]]
[[ALTER=replace:variable_name]]{value}[[ENDALTER]]
Action Numbers Text
add Adds the value Appends the value, after a space
remove Subtracts the value Removes the value from the text
replace Replaces the value Replaces the value

The variable must already exist. If it was set with [[VAR=...,save:true]], the changed value is saved.

CHANGE

Transforms the text between the tags. Chain several functions with |, applied left to right.

[[CHANGE=function_1|function_2(argument_1,argument_2)]]{text}[[ENDCHANGE]]
Function Effect
UPPERCASE Converts to upper case
LOWERCASE Converts to lower case
CAPITALIZE Capitalises the first letter
CAPITALIZE_ALL Capitalises the first letter of each word
TRIM Removes spaces from the start and end
REPLACE({find},{replace}) Replaces text. With no second argument, removes it.
PART({start},{length}) Returns part of the text. start counts from 0.
TRUNCATE({characters}) Shortens the text and adds an ellipsis
PLURALIZE({number},{suffix}) Adds a suffix unless the number is 1. Without {suffix}, adds "s".
NUMBER_IN_WORDS Writes a number in words: 25 becomes "twenty-five"
COUNT_CHARS Returns the number of characters
COUNT_WORDS Returns the number of words
ONLY_ALPHA Keeps only letters
ONLY_NUMBER Keeps only digits
PLAINTEXT Removes HTML tags
FOR_URL Lowercases, removes punctuation and replaces spaces with -
NO_LINES Removes line breaks
SAFE_LINES Replaces line breaks with ~~~
SAFE_LIST Stops a list being shown as bullet points when it's passed on as a variable
FORCE_LIST Shows a list as bullet points when it would otherwise be flat text
[[CHANGE=UPPERCASE]]{{a_counterparty_name}}[[ENDCHANGE]]
[[CHANGE=PLURALIZE({{days}})]]day[[ENDCHANGE]]
[[CHANGE=PLURALIZE({{children}},ren)]]child[[ENDCHANGE]]
[[CHANGE=TRIM|CAPITALIZE_ALL]]{{city}}[[ENDCHANGE]]

DATE

Formats a date, optionally after adding or subtracting time.

[[DATE={format}]]{timestamp_or_date}[[ENDDATE]]
[[DATE={format},{calculation}]]{timestamp_or_date}[[ENDDATE]]
  • {format} is a date format such as D MMMM YYYY, DD/MM/YYYY, ISO 8601, RFC 2822 or UNIX. See Date formats.
  • {calculation} is in {number} {unit} (or plus) to add time, or {number} {unit} ago to subtract it. Units are seconds, minutes, hours, days, weeks, months and years. Combine them with "and": in 1 year and 6 months.
  • Months are calendar months.
[[DATE=D MMMM YYYY]]{{*today}}[[ENDDATE]]                  5 January 2027
[[DATE=D MMMM YYYY,in 30 days]]{{a_date_start}}[[ENDDATE]]  30 days after the start date
[[DATE=UNIX,in 1 year]]{{*now}}[[ENDDATE]]                 a timestamp one year from now

MATH

Calculates the expression between the tags and formats the result.

[[MATH]]{expression}[[ENDMATH]]
[[MATH={option},{option}]]{expression}[[ENDMATH]]

The expression can use numbers, variables, +, -, *, / and brackets. Percentages are converted: 20% becomes 0.2. Currency symbols, commas, letters and spaces are ignored. If the expression can't be calculated, the output is a blank line.

Option Effect
decimals:{number} Number of decimal places. Default 2.
round:{up|down|ceiling|floor} How to round. Without it, the result is rounded to the nearest. ceiling and floor round to whole numbers.
currency:{symbol} Puts the symbol before the result, e.g. currency:£
percentage Puts % after the result
no_comma Leaves out the thousands separator
date_format:{format} Treats the result as a timestamp and formats it as a date. Use it with timestamps such as {{*now}}: date fields are already formatted as text by the time MATH runs, so use [[DATE]] for those.
[[MATH=currency:£,decimals:0]]{{salary}} * 12%[[ENDMATH]]          £5,400
[[MATH=decimals:1,percentage]]{{done}} / {{total}} * 100[[ENDMATH]]  87.5%
[[MATH=date_format:D MMMM YYYY]]{{*now}} + (90 * 86400)[[ENDMATH]]   the date in 90 days

MAP

Translates a value into a label, using a list of pairs.

[[MAP="{value}[:]{label}","{value}[:]{label}"]]{input}[[ENDMAP]]

If the input isn't in the list, it's output unchanged.

[[MAP="ft[:]Full-time","pt[:]Part-time"]]{{hours_type}}[[ENDMAP]]

INCLUDE

Embeds other content.

[[INCLUDE={type}:{target}]]
[[INCLUDE={type}({options}):{target}]]
[[INCLUDEIF={variable}({condition}),{type}:{target}]]
[[INCLUDENOT={variable}({condition}),{type}:{target}]]
Type Embeds
document:{document_key} Another Plainly document, shown in a frame
document_data:{document_key} Only the variables from another document
template:{template_key} The text of another template, such as a standard clause or a letterhead
image:{url} An image
image({width}x{height}):{url} An image at a set size. Use image({width}): or image(x{height}): to set one side only.
data({options}):{https_url} JSON data as variables. See Pulling data into documents.
widget({options}) A table, summary table or score. See Widget reference.

[[INCLUDEIF]] includes the content only when the condition is met. [[INCLUDENOT]] includes it only when it isn't. The condition is optional: [[INCLUDEIF=has_logo,image:{{logo_url}}]].

Layout statements

Statement Effect
[[SIGNATURE_BLOCK]] Places the signature blocks. Without it, they go at the end.
[[DEED_BLOCK]] Places the execution block of a deed
[[SUBMIT_BUTTON]] Places a form's submit button
[[SAVE]] A save button, for editable fields on web pages and sent documents
[[PAGEBREAK]] Starts a new page when printed or saved as a PDF
[[PAGENO]], [[PAGETOTAL]] The page number and the number of pages, in PDF footers
[[LINK={url}]]{text}[[ENDLINK]] A link
[[BUTTON={url}]]{text}[[ENDBUTTON]] A link styled as a button
[[MARKER={name}]] An anchor, so you can link to #name
[[AT={html_tag}]]{text}[[ENDAT]] Wraps the text in an HTML tag, e.g. [[AT=strong]]Important[[ENDAT]]
[[BLANK]] Outputs nothing. Useful as a placeholder.

Escaping commas and pipes

Inside [[CHANGE]], [[DATE]], [[REPEAT]] and widget options, commas and pipes separate arguments. To use a literal comma or pipe, write ,::ok or |::ok:

[[CHANGE=REPLACE(;,,::ok)]]{{list}}[[ENDCHANGE]]

Order of processing

Plainly processes statements in this order. It explains which statements can go inside which:

  1. [[VAR]]
  2. [[REPEAT]]
  3. [[INCLUDENOT]], [[INCLUDEIF]], then [[INCLUDE]]
  4. [[PAGEBREAK]]
  5. [[NOT]]
  6. [[IF]], [[ELSEIF]], [[ELSE]]
  7. [[AT]], [[LINK]], [[BUTTON]], [[SAVE]], [[MARKER]]
  8. [[ALTER]]
  9. {{variables}}
  10. [[MAP]], then [[DATE]], then [[CHANGE]]
  11. [[MATH]]

Because variables are filled in before MAP, DATE, CHANGE and MATH run, you can put variables inside those statements. Because MATH runs last, it can calculate with the output of DATE or CHANGE.

For AI builders

Common mistakes to avoid:

  • Writing AND/OR inside one IF. Use a Hidden item or [[VAR]] to work out a combined value, then test that.
  • Nesting IF inside IF. Use ELSEIF, or put the inner test in a NOT, or precompute.
  • Using IS_BLANK in an IF. Use [[NOT=variable]].
  • Forgetting fallback text on optional variables.
  • Testing true/false variables with a bare IF. Use (EQUALS true).