Scriptlets Reference: Conditions, Filters and Loops in Form Notifications
A scriptlet is a short instruction that you type inside your template. It can show text only when a condition is true, change an answer before it is printed, do arithmetic, or repeat a line for each item in a list. Form Notifications runs the scriptlets for each response, after it fills in the markers.
Scriptlets use Liquid, a template language that many email and website tools share. You don’t need to know how to program. Most templates need only two or three of the tags on this page.
The same scriptlets work in Mail Merge, Form Notifications and Document Studio. A template that you write for one add-on works in the other two.
The Two Forms of a Scriptlet
Section titled “The Two Forms of a Scriptlet”| Form | Written as | What it does | Example |
|---|---|---|---|
| Tag | {% … %} |
Makes a decision, repeats text or stores a value. A tag prints nothing itself. | {% if {{Plan}} == "Pro" %} |
| Output | {? … ?} |
Prints a value, often after a filter has changed it | {? {{Your name}} | upcase ?} |
Markers keep their double curly braces inside a scriptlet. The output form uses {? and ?} because {{ and }} already mean a marker.
The Example on This Page
Section titled “The Example on This Page”Maya runs Willow Lane Studio. Her membership form has these questions, and every example uses Sofia’s response.
| Question | Sofia’s answer |
|---|---|
Your name |
sofia marquez |
Plan |
Pro |
Seats |
3 |
Amount |
49.5 |
City |
Lisbon |
Notes |
(empty) |
Interests |
Pottery, Weaving and Glass ticked (Checkboxes) |
Event date |
Mar 14, 2027 |
Bio |
Maker of small things, teacher, and a slow runner who likes long walks |
Conditions
Section titled “Conditions”if, elsif and else
Section titled “if, elsif and else”{% if %} shows the text up to {% endif %} only when the condition is true. {% else %} gives the text for every other case, and {% elsif %} adds another condition in between.
{% if {{Plan}} == "Team" %}Your team space is ready.{% elsif {{Plan}} == "Pro" %}Your Pro membership is active.{% else %}You are on the free plan.{% endif %}Sofia reads Your Pro membership is active.
Comparisons
Section titled “Comparisons”| You write | True for Sofia | True when |
|---|---|---|
{% if {{Plan}} == "Pro" %} |
Yes | The answer is exactly Pro |
{% if {{Plan}} == "pro" %} |
No | Capital letters must match |
{% if {{Plan}} != "Free" %} |
Yes | The answer is anything else, or empty |
{% if {{Seats}} > 2 %} |
Yes | The answer is a number above 2 |
{% if {{Seats}} >= 3 %} |
Yes | 3 or more |
{% if {{Seats}} < 3 %} |
No | A number below 3 |
{% if {{Seats}} <= 3 %} |
Yes | 3 or less |
{% if {{Notes}} == "" %} |
Yes | The answer is empty |
{% if {{Notes}} != "" %} |
No | The answer is not empty |
{% if {{Interests}} contains "Weaving" %} |
Yes | The text is somewhere in the answer |
Text goes in straight quotes. Numbers have no quotes. An answer that looks like a number is a number, so {{Seats}} == 3 is true and {{Seats}} == "3" is false.
and, or
Section titled “and, or”{% if {{Plan}} == "Pro" and {{Seats}} > 5 %}You qualify for the group rate.{% endif %}
{% if {{Plan}} == "Pro" or {{Plan}} == "Team" %}Thanks for being a paying member.{% endif %}Sofia has 3 seats, so she reads only the second sentence.
unless
Section titled “unless”{% unless %} is the opposite of {% if %}. The text shows when the condition is false.
{% unless {{Plan}} == "Free" %}Your invoice is attached.{% endunless %}case and when
Section titled “case and when”{% case %} compares one answer with a list of values. It is shorter than a long chain of {% elsif %}.
{% case {{Plan}} %}{% when "Free" %}Upgrade any time from your account page.{% when "Pro", "Team" %}Your next invoice is on the 1st.{% else %}Contact us to set up your plan.{% endcase %}A {% when %} can list several values with commas between them.
Empty Values
Section titled “Empty Values”| You write | Result |
|---|---|
{% if {{Notes}} == "" %} |
True when the answer is empty. Use this form. |
{% if {{Notes}} != "" %} |
True when the answer has something in it |
{% if {{Notes}} %} |
True for every response, even when the answer is empty. Don’t use this form. |
A marker with no matching question also counts as empty.
Print and Change a Value
Section titled “Print and Change a Value”{? … ?} prints a value. A filter after a | changes the value first. Filters can follow each other, and each one works on the result of the one before:
Hi {? {{Your name}} | split: " " | first | capitalize ?},Text Filters
Section titled “Text Filters”| You write | Output | What it does |
|---|---|---|
{? {{Your name}} | upcase ?} |
SOFIA MARQUEZ |
Capital letters |
{? {{Your name}} | downcase ?} |
sofia marquez |
Small letters |
{? {{Your name}} | capitalize ?} |
Sofia marquez |
A capital first letter, small letters after |
{? {{Your name}} | append: "!" ?} |
sofia marquez! |
Adds text at the end |
{? {{Your name}} | prepend: "Dr. " ?} |
Dr. sofia marquez |
Adds text at the start |
{? {{Your name}} | replace: "sofia", "Sofia" ?} |
Sofia marquez |
Replaces every match |
{? {{Your name}} | replace_first: "a", "A" ?} |
sofiA marquez |
Replaces the first match only |
{? {{Your name}} | remove: "sofia " ?} |
marquez |
Removes every match |
{? {{Your name}} | slice: 0, 5 ?} |
sofia |
5 characters, starting at the first |
{? {{Your name}} | size ?} |
13 |
The number of characters |
{? {{Bio}} | truncate: 30 ?} |
Maker of small things, teac... |
Cuts to 30 characters, including the dots |
{? {{Bio}} | truncatewords: 5 ?} |
Maker of small things, teacher,... |
Cuts to 5 words |
{? " hi " | strip ?} |
hi |
Removes spaces at both ends |
{? {{Notes}} | default: "None" ?} |
None |
Text to use when the answer is empty |
{? {{City}} | url_encode ?} |
Lisbon |
Makes text safe to put in a link |
{? "<b>Hi</b>" | strip_html ?} |
Hi |
Removes HTML tags |
{? "<b>Hi</b>" | escape ?} |
<b>Hi</b> |
Shows HTML as text |
Also available: lstrip, rstrip, strip_newlines, remove_first, url_decode and escape_once.
A full name with capital letters needs a short loop, because capitalize changes only the first letter:
{% assign words = {{Your name}} | split: " " %}{% for word in words %}{? word | capitalize ?} {% endfor %}Number Filters
Section titled “Number Filters”| You write | Output | What it does |
|---|---|---|
{? {{Seats}} | plus: 1 ?} |
4 |
Adds |
{? {{Seats}} | minus: 1 ?} |
2 |
Subtracts |
{? {{Seats}} | times: 20 ?} |
60 |
Multiplies |
{? {{Amount}} | times: {{Seats}} ?} |
148.5 |
Multiplies two answers |
{? {{Amount}} | divided_by: 4 ?} |
12.375 |
Divides |
{? 7 | modulo: 2 ?} |
1 |
The remainder of a division |
{? {{Amount}} | round ?} |
50 |
Rounds to a whole number |
{? 3.14159 | round: 2 ?} |
3.14 |
Rounds to 2 decimal places |
{? {{Amount}} | ceil ?} |
50 |
Rounds up |
{? {{Amount}} | floor ?} |
49 |
Rounds down |
{? -5 | abs ?} |
5 |
Removes the minus sign |
{? {{Seats}} | at_least: 5 ?} |
5 |
The value, or 5 if the value is lower |
{? {{Seats}} | at_most: 2 ?} |
2 |
The value, or 2 if the value is higher |
Things to watch with numbers:
- A number with a comma, a currency sign or a unit is text.
$1,200is not above 1000. Remove the signs first:{? "$1,200" | remove: "$" | remove: "," | plus: 0 ?}gives1200. - There is no filter that always prints two decimals.
148.5stays148.5, not148.50. - Arithmetic with decimals can give a long tail, such as
0.30000000000000004. End withround: 2. - To add a currency sign, use
prepend:{? {{Amount}} | times: {{Seats}} | prepend: "$" ?}gives$148.5.
Date Filters
Section titled “Date Filters”The date filter prints a date in the format that you give.
| You write | Output |
|---|---|
{? {{Event date}} | date: "%B %d, %Y" ?} |
March 14, 2027 |
{? {{Event date}} | date: "%A, %-d %b %Y" ?} |
Sunday, 14 Mar 2027 |
{? {{Event date}} | date: "%d/%m/%Y" ?} |
14/03/2027 |
{? {{Event date}} | date: "%Y-%m-%d" ?} |
2027-03-14 |
{? {{Event date}} | date: "%A" ?} |
Sunday |
{? "now" | date: "%B %Y" ?} |
The current month and year |
| Code | Meaning | Example |
|---|---|---|
%Y |
Year, 4 digits | 2027 |
%y |
Year, 2 digits | 27 |
%B |
Month name | March |
%b |
Short month name | Mar |
%m |
Month number, 2 digits | 03 |
%d |
Day, 2 digits | 14 |
%-d |
Day, no leading zero | 14 |
%A |
Weekday name | Sunday |
%a |
Short weekday name | Sun |
%H |
Hour, 24-hour clock | 09 |
%I |
Hour, 12-hour clock | 09 |
%M |
Minutes | 05 |
%p |
AM or PM | AM |
To add days to a date, turn it into seconds, add, and format it again. One day is 86400 seconds:
Reply by {? {{Event date}} | date: "%s" | plus: 604800 | date: "%b %e, %Y" ?}A Date answer reaches the scriptlet in the format from Form Settings. The date filter can read the default format, Mar 14, 2027. "now" is the moment the notification is sent, in UTC.
A list is several values in one answer, such as the ticked options of a Checkboxes question. Form Notifications keeps the options of one answer apart with <BR/>. split turns the text into a list, and the list filters work on it.
| You write | Output | What it does |
|---|---|---|
{? {{Interests}} | split: "<BR/>" | join: " + " ?} |
Pottery + Weaving + Glass |
Joins the items with other text |
{? {{Interests}} | split: "<BR/>" | size ?} |
3 |
Counts the items |
{? {{Interests}} | split: "<BR/>" | first ?} |
Pottery |
The first item |
{? {{Interests}} | split: "<BR/>" | last ?} |
Glass |
The last item |
{? {{Interests}} | split: "<BR/>" | sort | join: ", " ?} |
Glass, Pottery, Weaving |
Sorts the items |
{? {{Interests}} | split: "<BR/>" | reverse | join: ", " ?} |
Glass, Weaving, Pottery |
Reverses the order |
Also available: uniq removes repeated items, concat joins two lists, sum adds a list of numbers and sort_natural sorts without regard to capital letters.
{% for %} repeats the text up to {% endfor %} once for each item in a list. Store the list with {% assign %} first.
{% assign interests = {{Interests}} | split: "<BR/>" %}You chose:{% for item in interests %}{? forloop.index ?}. {? item ?}{% endfor %}Sofia reads:
You chose:1. Pottery2. Weaving3. Glass| Inside a loop | What it gives |
|---|---|
{? forloop.index ?} |
The number of this round, from 1 |
{? forloop.length ?} |
The number of items |
{% if forloop.first %} |
True in the first round |
{% if forloop.last %} |
True in the last round |
{% break %} |
Stops the loop |
{% continue %} |
Skips to the next item |
{% else %} before {% endfor %} |
Text to show when the list is empty |
| Loop | Output for Sofia |
|---|---|
{% for item in interests limit: 2 %} |
Pottery, Weaving |
{% for item in interests offset: 1 %} |
Weaving, Glass |
{% for item in interests reversed %} |
Glass, Weaving, Pottery |
{% for i in (1..3) %} |
1, 2, 3 |
{% for i in (1..{{Seats}}) %} |
1, 2, 3, because Sofia has 3 seats |
A loop over numbers prints one line for each seat:
{% for i in (1..{{Seats}}) %}Seat {? i ?} of {? {{Seats}} ?}{% endfor %}Variables
Section titled “Variables”{% assign %} stores a value under a name that you choose. Use the name later without braces.
{% assign total = {{Amount}} | times: {{Seats}} %}Your total is ${? total ?}.{% if total > 100 %}You get free delivery.{% endif %}Sofia reads Your total is $148.5. and You get free delivery.
A filter can’t go inside {% if %}. Store the filtered value first:
{% assign plan = {{Plan}} | downcase %}{% if plan == "pro" %}Thanks for going Pro.{% endif %}This also makes a comparison ignore capital letters.
{% capture %} stores a block of text, with its markers and scriptlets filled in:
{% capture greeting %}Hi {? {{Your name}} | split: " " | first | capitalize ?}{% endcapture %}{? greeting ?}, welcome to the studio.{? greeting ?}, your invoice is attached.Other Tags
Section titled “Other Tags”| Tag | What it does |
|---|---|
{% comment %} … {% endcomment %} |
A note to yourself. Nothing between the tags is printed. |
{% raw %} … {% endraw %} |
Prints the text between the tags as typed, without running it |
{% echo {{Plan}} | upcase %} |
The same as {? {{Plan}} | upcase ?} |
{% cycle "odd", "even" %} |
Inside a loop, prints the next value of the list in each round |
{% increment n %}, {% decrement n %} |
Prints a counter that goes up or down each time |
{% tablerow item in list %} … {% endtablerow %} |
Prints the items as cells of an HTML table row |
Remove Extra Blank Lines
Section titled “Remove Extra Blank Lines”A tag on a line of its own leaves an empty line where it stood. Add a hyphen inside the tag to remove the white space on that side:
{%- if {{Plan}} == "Pro" -%}Pro member{%- endif -%}Not Available
Section titled “Not Available”{% include %},{% render %}and{% layout %}load other template files. They are turned off, and a template that has one fails withtag "include" not found.- An answer is never read as a scriptlet. If a respondent types text that holds
{% if %}, the output shows that text. - A marker can’t hold a scriptlet inside its braces.
Where Scriptlets Work in Form Notifications
Section titled “Where Scriptlets Work in Form Notifications”| Place | Scriptlets run |
|---|---|
| Email Subject and Email Body | Yes |
| PDF File Name and PDF Template | Yes |
| Slack, Discord and Google Chat messages | Yes |
| SMS and push notification text | Yes |
| Sender’s Name, recipients and Reply-to Email Address | Yes, but keep these to plain markers |
| Webhook URL, headers and body | No |
| AI prompts in AI Studio | Yes |
Scriptlets are for the content of a message. To choose who gets the email, use conditional notifications.
Tips for Form Answers
Section titled “Tips for Form Answers”- A Checkboxes answer holds every ticked option. Use
containsto test for one option, andsplit: "<BR/>"to loop over them. - A Multiple choice grid answer has one line for each row, as
Row (Column), with<BR/>between the lines. - A quiz gives you
{{Quiz Score}}and{{Quiz Score Percent}}as numbers:{% if {{Quiz Score Percent}} >= 60 %}You passed.{% endif %} - A QR code or a picture inside an
{% if %}is added only when the condition is true:{% if {{Plan}} == "Pro" %}{{Embed QR Code, {{Response ID}}}}{% endif %} - In the visual editor, type tags as plain text. If part of a tag is bold or coloured, the tag stops working.
When a Scriptlet Has a Mistake
Section titled “When a Scriptlet Has a Mistake”Form Notifications does not hold back a notification because of a scriptlet mistake. It sends the message with the markers filled in and the tags left as typed, so the response still reaches you. You see the mistake as tags in the email.
Submit a test response after every change to a scriptlet, and read the email that arrives.
Troubleshooting
Section titled “Troubleshooting”The condition is never true
Section titled “The condition is never true”- Check the capital letters.
Prois notpro. To ignore them, store the value withdowncasefirst. - Check for quotes. Text needs straight quotes, as in
"Pro". Without quotes, the condition is false and no error shows. - For
>and<, the answer must be a plain number with no comma, currency sign or unit. - A number has no quotes.
{{Seats}} == "3"is false when the answer is the number 3.
“expected “|” before filter”
Section titled ““expected “|” before filter””The tag has something that Liquid can’t read. The usual causes are curly quotes such as “Pro”, a filter inside an {% if %}, or a tag that is partly bold or coloured. Type the tag again as plain text with straight quotes.
“tag {% if … %} not closed”
Section titled ““tag {% if … %} not closed””An {% if %}, {% for %}, {% case %}, {% unless %} or {% capture %} has no closing tag. Each one needs its own {% endif %}, {% endfor %}, {% endcase %}, {% endunless %} or {% endcapture %}.
The condition with “and” and “or” gives the wrong result
Section titled “The condition with “and” and “or” gives the wrong result”Liquid reads and and or from right to left and has no brackets. Split the condition into two {% if %} tags, one inside the other.
The date filter prints the date unchanged
Section titled “The date filter prints the date unchanged”The filter can’t read the date. It reads forms such as 2027-03-14 and Mar 14, 2027. It can’t read 14/03/2027.
The output has empty lines
Section titled “The output has empty lines”Each tag on its own line leaves a line break behind. Use the hyphen form, {%- … -%}, or put the tag on the same line as the text.
