Skip to content
Digital Inspiration DocsDigital Inspiration Docs

A scriptlet is a short instruction that you type inside your template. It can show text only when a condition is true, change a value before it is printed, do arithmetic, or repeat a line for each item in a list. Document Studio runs the scriptlets for each row, 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.

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.

Maya runs Willow Lane Studio. Her members sheet has these columns, and every example uses Sofia’s row.

Column Sofia’s cell
Your name sofia marquez
Plan Pro
Seats 3
Amount 49.5
City Lisbon
Notes (empty)
Interests Pottery, Weaving, Glass
Event date Mar 14, 2027
Bio Maker of small things, teacher, and a slow runner who likes long walks

{% 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.

You write True for Sofia True when
{% if {{Plan}} == "Pro" %} Yes The cell is exactly Pro
{% if {{Plan}} == "pro" %} No Capital letters must match
{% if {{Plan}} != "Free" %} Yes The cell is anything else, or empty
{% if {{Seats}} > 2 %} Yes The cell 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 cell is empty
{% if {{Notes}} != "" %} No The cell is not empty
{% if {{Interests}} contains "Weaving" %} Yes The text is somewhere in the cell

Text goes in straight quotes. Numbers have no quotes. A cell that looks like a number is a number, so {{Seats}} == 3 is true and {{Seats}} == "3" is false.

{% 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 %} is the opposite of {% if %}. The text shows when the condition is false.

{% unless {{Plan}} == "Free" %}
Your invoice is attached.
{% endunless %}

{% case %} compares one cell 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.

You write Result
{% if {{Notes}} == "" %} True when the cell is empty. Use this form.
{% if {{Notes}} != "" %} True when the cell has something in it
{% if {{Notes}} %} True for every row, even when the cell is empty. Don’t use this form.

A marker with no matching column also counts as empty.

{? … ?} 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 ?},
Output
Hi Sofia,
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 cell 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 ?} &lt;b&gt;Hi&lt;/b&gt; 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 %}
Output
Sofia Marquez
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 cells
{? {{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,200 is not above 1000. Remove the signs first: {? "$1,200" | remove: "$" | remove: "," | plus: 0 ?} gives 1200.
  • There is no filter that always prints two decimals. 148.5 stays 148.5, not 148.50.
  • Arithmetic with decimals can give a long tail, such as 0.30000000000000004. End with round: 2.
  • To add a currency sign, use prepend: {? {{Amount}} | times: {{Seats}} | prepend: "$" ?} gives $148.5.

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" ?}
Output
Reply by Mar 21, 2027

A scriptlet gets a date as the cell shows it. The date filter can read 2027-03-14, Mar 14, 2027 and 3/14/2027. It can’t read a date that starts with the day, such as 14/03/2027. "now" is the moment the task runs, in UTC, not in your spreadsheet’s time zone.

A list is several values in one cell, such as Pottery, Weaving, Glass. split turns the text into a list, and the list filters work on it.

You write Output What it does
{? {{Interests}} | split: ", " | join: " + " ?} Pottery + Weaving + Glass Joins the items with other text
{? {{Interests}} | split: ", " | size ?} 3 Counts the items
{? {{Interests}} | split: ", " | first ?} Pottery The first item
{? {{Interests}} | split: ", " | last ?} Glass The last item
{? {{Interests}} | split: ", " | sort | join: ", " ?} Glass, Pottery, Weaving Sorts the items
{? {{Interests}} | split: ", " | 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: ", " %}
You chose:
{% for item in interests %}
{? forloop.index ?}. {? item ?}
{% endfor %}

Sofia reads:

You chose:
1. Pottery
2. Weaving
3. 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 %}

{% 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.
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

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 -%}
  • {% include %}, {% render %} and {% layout %} load other template files. They are turned off, and a template that has one fails with tag "include" not found.
  • A cell is never read as a scriptlet. If a cell holds {% if %}, the output shows that text.
  • A marker can’t hold a scriptlet inside its braces.
Place Scriptlets run
Send Email: the subject and the message body Yes
Create File: the file name, the subfolder path and the PDF password Yes
A Google Sheets template: the text of each cell Yes
Fill PDF Forms: the value of each form field Yes
Messages for Slack, Google Chat, Discord, Telegram, SMS and IFTTT Yes
Other text boxes of a task, such as the items of an invoice Yes
The body of a Google Docs or Google Slides template No

A Google Docs template has its own way to show or hide a section. See Conditional Content in Google Docs. To decide whether a row is processed at all, use the workflow’s conditions.

  • A scriptlet reads the text of a cell, as the sheet shows it. A cell that shows $1,200 gives the text $1,200, not the number.
  • In the email body, what {? … ?} prints is shown as text. HTML that a filter writes, such as the <br> from newline_to_br, appears as typed.
  • In the other places, Document Studio removes HTML tags from the result.
  • An Embed marker inside an {% if %} runs only when the condition is true. A picture, a chart or a file in a part of the email that the condition drops is not attached.
  • A Checkboxes answer from Google Forms arrives as one cell with commas between the options. Use contains to test for one option, and split: ", " to loop over them.

What happens depends on where the scriptlet is:

  • In the subject or the body of an email, Document Studio stops the Send Email task for that row and sends nothing. The error tells you what to fix. See the error messages.
  • In any other place, such as a file name or a Slack message, Document Studio treats the box as empty. A file then gets the name of its template.

Preview the task after every change to a scriptlet. A preview shows the error without touching your rows.

  1. Check the capital letters. Pro is not pro. To ignore them, store the value with downcase first.
  2. Check for quotes. Text needs straight quotes, as in "Pro". Without quotes, the condition is false and no error shows.
  3. For > and <, the cell must be a plain number with no comma, currency sign or unit.
  4. A number has no quotes. {{Seats}} == "3" is false when the cell is the number 3.

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.

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

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.