A filter changes a value before it is shown or stored. Filters are written after a pipe |, and some take extra information (arguments) after a colon.

1
2
3
{{ "hobbit" | upcase }}
{{ "The Hobbit" | replace: "Hobbit", "Kraken" }}
{{ "aaah" | capitalize | append: "!" }}
1
2
3
HOBBIT
The Kraken
AAAH!

There are various types of filter:

  • Text
  • Numbers and maths
  • Arrays
  • Dates
  • Escaping and encoding
  • Fallback values

Text filters

These filters work on strings.

Changing case

upcase

Syntax: string | upcase

Changes every letter to capitals.

1
{{ "Hello World" | upcase }}  # HELLO WORLD

downcase

Syntax: string | downcase

Changes every letter to lower case.

1
{{ "Hello World" | downcase }}   # hello world

Useful for making comparisons that need to ignore case:

1
2
{% assign status_lower = status | downcase %}
{% if status_lower == "live" %}...{% endif %}

capitalize

Syntax: string | capitalize

Capitalises the first letter of the first word, and lowercases the rest.

1
{{ "hello WORLD" | capitalize }}   # Hello world

Adding text

append

Syntax: string | append: text

Adds text to the end of a string.

1
2
{{ "416" | append: "pp" }}   # 416pp
{{ 5 | append: "%" }}        # 5%

prepend

Syntax: string | prepend: text

Adds text to the start of a string.

1
{{ format_name | prepend: "Format: " }}   # Format: hardback

Replacing and removing

Case sensitive.

1
2
3
4
5
6
{{ "The Hobbit!e!" | replace: "!", "s" }}       # The Hobbitses
{{ "The Hobbit!"   | replace_first: "b", "-" }} # The Ho-bit!
{{ "The Hobbit!"   | replace_last: "b", "-" }}  # The Hob-it!
{{ "The Hobbit!"   | remove: "b" }}             # The Hoit
{{ "The Hobbit!"   | remove_first: "b" }}       # The Hobit!
{{ "The Hobbit!"   | remove_last: "b" }}        # The Hobit!

truncate

Syntax: string | truncate: length, ending

Shortens a string to at most length characters. Defaults to 50 characters.

1
2
3
4
{{ "The Lord of the Rings" | truncate: 20 }}        # The Lord of the R...
{{ "The Lord of the Rings" | truncate: 20, "!" }}   # The Lord of the Rin!
{{ "The Lord of the Rings" | truncate: 20, "" }}    # The Lord of the Ring
{{ "The Hobbit" | truncate: 20 }}                   # The Hobbit

truncatewords

Syntax: string | truncatewords: count, ending

Shortens a string to at most count words. Defaults to 15. HTML tags count as words but they can be removed first with strip_html.

1
2
3
{{ "The quick brown fox jumps" | truncatewords: 3 }}              # The quick brown...
{{ "The quick brown fox jumps" | truncatewords: 3, " [more]" }}   # The quick brown [more]
{{ "The quick brown" | truncatewords: 5 }}                        # The quick brown

Splitting and measuring

split

Syntax: string | split: separator

Cuts a string into an array of pieces wherever the separator appears.

1
2
3
{% assign subjects = "crime,horror,fantasy" | split: "," %}
{{ subjects[1] }}     # horror
{{ subjects.size }}   # 3

size

Syntax: value | size

Returns the number of characters in a string, or the number of items in an array.

1
2
3
{{ "Hello" | size }}      # 5
{{ subjects | size }}     # 3
{{ subtitle | size }}     # 0   (when the subtitle has no value)

Whitespace

strip, lstrip and rstrip

Syntax: string | strip or string | lstrip or string | rstrip

Remove spaces, tabs and line breaks from either side of a string.

1
2
3
[{{ "  hi  " | strip }}]    # [hi]
[{{ "  hi  " | lstrip }}]   # [hi  ]
[{{ "  hi  " | rstrip }}]   # [  hi]

Whitespace in the middle of the string is not removed.

strip_newlines

Syntax: string | strip_newlines

Removes all line breaks from a string.

If text is

1
2
one
two
1
{{ text | strip_newlines }}   # onetwo

newline_to_br

Syntax: string | newline_to_br

Puts an HTML break tag (<br />) in front of every line break in a string.

If text is

1
2
one
two
1
{{ text | newline_to_br }}
1
2
one<br />
two

strip_html

Syntax: string | strip_html

Removes HTML tags from a string, but leaves the text untouched.

1
{{ "<p>Hello <b>world</b></p>" | strip_html }}   # Hello world

Consonance specific

These are not part of standard Liquid.

csv_encode

Syntax: string | csv_encode

Formats a string so it can be included in a CSV file, by replacing double quotes with two double quotes, and wrapping the string in double quotes if it contains a comma or newline.

Pass true as the first parameter to always wrap the string in double quotes.

1
2
3
{{ "string" | csv_encode }}         # string
{{ "string" | csv_encode: true }}   # "string"
{{ "string, string" | csv_encode}}  # "string"

markup

Syntax: string | markup "em"

Wraps a string in opening and closing tags, and escapes any characters not valid for inclusion in HTML or XML.

Attributes can also be included as part of the markup string

1
2
{{ work.title | markup: "em"}}                 # <em>The Hobbit</em>
{{ work.title | markup: "th class='heading'"}} # <th class='heading'>The Hobbit</th>

to_sentence

Syntax: array | to_sentence: words_connector, last_word_connector, two_words_connector

Turns an array of values into a sentence fragment, with optional choice of how to connect the elements.

1
2
3
4
5
6
{%- assign array = "AA;BB;C;DD;C;BB;AAA" | split: ";" %}
{{ array | to_sentence }}                        # AA, BB, C, DD, C, BB, and AAA
{{ array | to_sentence: ", ", " and " }}         # AA, BB, C, DD, C, BB and AAA
{{ array | to_sentence: ", ", " et " }}          # AA, BB, C, DD, C, BB et AAA
{%- assign array2 = "AA;BB" | split: ";" %}
{{ array2 | to_sentence: ", ", " et ", " et " }} # AA et BB

min_by and max_by

Syntax: array | min_by: comparison_property, array | max_by: comparison_property

Sort the array according to the comparison property, then min_by takes the first element and max_by takes the last element.

1
2
3
{%- assign array = "AA;BB;C;DD;C;BB;AAA" | split: ";" %}
{{ array | min_by: "size" }} # C
{{ array | max_by: "size" }} # AAA

Maths filters

  • If either number in a calculation is a decimal, the answer is a decimal.
  • Text that looks like a number is converted: {{ "5" | plus: 1 }} gives 6.
  • Text that is not a number counts as 0. {{ "abc" | plus: 1 }} gives 1, with no error. Text that starts with digits uses those digits: "12abc" counts as 12.
  • Filters run from left to right, with no multiplication before addition rule. {{ 2 | plus: 3 | times: * 4 }} gives 20, because it works out (2 + 3) × 4. To get 2 + (3 × 4), put the multiplication first: {{ 3 | times: 4 | plus: 2 }} gives 14.
  • Decimals can show tiny rounding errors. {{ 0.1 | plus: 0.2 }} can print 0.30000000000000004. Tidy a result with round.

Arithmetic

plus, minus and times

Syntax: number | plus: number or number | minus: number or number | times: number

1
2
3
4
5
{{ 4 | plus: 2 }}       # 6
{{ 10 | minus: 4 }}     # 6
{{ 3 | times: 4 }}      # 12
{{ 3 | times: 0.5 }}    # 1.5
{{ "4" | plus: "3" }}   # 7

divided_by

Syntax: number | divided_by: number

Divides the first number by the second.

1
2
3
4
{{ 10 | divided_by: 4 }}     # 2
{{ 10 | divided_by: 4.0 }}   # 2.5
{{ 7.5 | divided_by: 2 }}    # 3.75
{{ -7 | divided_by: 2 }}     # -4

Whole number ÷ whole number gives a whole number, with the remainder thrown away, and the result is rounded down. That is why 10 ÷ 4 is 2, and -7 ÷ 2 is -4. If you want a decimal answer, make one of the numbers a decimal (4.0, not 4). - Dividing by zero raises an error.

modulo

Syntax: number | modulo: number

Returns the remainder left over after dividing the first number by the second.

1
2
{{ 10 | modulo: 3 }}   # 1
{{ 12 | modulo: 4 }}   # 0

Rounding

round

Syntax: number | round: places

Rounds to the nearest whole number, or to places decimal places if you give a number.

1
2
3
4
5
6
{{ 4.6    | round }}          # 5
{{ 4.4    | round }}          # 4
{{ 2.5    | round }}          # 3
{{ 4.5678 | round: 2 }}    # 4.57
{{ 1234   | round: -2 }}     # 1200
{{ 0.1    | plus: 0.2 | round: 2 }}   # 0.3

ceil and floor

Syntax: number | ceil or number | floor

1
2
3
4
{{ 4.1  | ceil }}     # 5
{{ -4.1 | ceil }}    # -4
{{ 4.9  | floor }}    # 4
{{ -4.1 | floor }}   # -5

Use this to work out how many pages are needed: {{ items | divided_by: 20.0 | ceil }} gives the number of pages of 20 items.


Limits and signs

abs

Syntax: number | abs

Returns the number’s absolute value.

1
2
3
{{ -5   | abs }}     # 5
{{ -4.5 | abs }}     # 4.5
{{ 3    | abs }}     # 3

at_least

Syntax: number | at_least: minimum

Prints the number or, if the number is smaller, the minimum.

1
2
{{ 3 | at_least: 5 }}   # 5
{{ 8 | at_least: 5 }}   # 8

at_most

Syntax: number | at_most: maximum

Prints the number or, if the number is smaller, the maximum.

1
2
{{ 8 | at_most: 5 }}   # 5
{{ 3 | at_most: 5 }}   # 3

To keep a number between two limits, use both: {{ n | at_least: 1 | at_most: 10 }}.


Examples

To get a percentage, use a decimal divisor to avoid whole-number rounding:

1
{{ 25 | times: 100 | divided_by: 200.0 }}%   # 12.5%

Array filters

These filters work on arrays which are ordered lists of values.

In this section:

  • colours is an array of strings: red, green, blue, yellow, purple.
  • people is an array of objects, each with a name, a team and an age:
1
2
3
4
April: { team: red,  age: 31}
Ben:   { team: blue, age: 25}
Chloe: { team: red,  age: 40}
David: { team: blue, age: 28}
  • Filters return a new array; the original is left unchanged.
  • Chain filters: {{ people | where: "team", "red" | map: "name" | join: ", " }}
  • Properties are named in quotes.** In where: "team", "red", "team" is the name of a property that each item has, and "red" is the value to look for.
  • Nested arrays are flattened into one array, and a single value that isn’t an array is treated as an array of one item.

Picking items

first and last

Syntax: array | first or array | last

Return the first or the last item of an array.

1
2
3
{{ colours | first }}              # red
{{ colours | last }}               # purple
{{ colours | sort | first }}       # blue

slice

Syntax: array | slice: start, length

Returns a part of an array, starting at position start (counting from 0) and running for length items. A negative start counts back from the end.

1
2
{{ colours | slice: 1, 2 | join: ", " }}    # green, blue
{{ colours | slice: -2, 2 | join: ", " }}   # yellow, purple

find

Syntax: array | find: property, value

Returns the first item whose property equals value.

1
2
{% assign first_blue = people | find: "team", "blue" %}
{{ first_blue.name }}   # Ben

find_index

Syntax: array | find_index: property, value

Returns the position (counting from 0) of the first item whose property equals value, or nil if none do.

1
{{ people | find_index: "team", "blue" }} # 1

Filtering

where

Syntax: array | where: property, value

Keeps only the items whose property equals value.

1
{{ people | where: "team", "red" | map: "name" | join: ", " }}   # April, Chloe

Leave out the value to keep the items whose property has any value that counts as true:

1
{{ people | where: "nickname" | map: "name" | join: ", " }}

reject

Syntax: array | reject: property, value

The opposite of where: keeps the items whose property does not equal value.

1
{{ people | reject: "team", "red" | map: "name" | join: ", " }}   # Ben, David

Without a value, it removes the items whose property has a value that counts as true.

has

Syntax: array | has: property, value

If at least one item has a property equal to value, returns true, else false.

1
2
{{ people | has: "team", "red" }}     # true
{{ people | has: "team", "green" }}   # false

A filter can’t be used directly inside an if, so assign the result to a variable first:

1
2
{% assign has_red = people | has: "team", "red" %}
{% if has_red %}There is a red team.{% endif %}

Rearranging

sort

Syntax: array | sort or array | sort: property

Puts the items in ascending order. For an array of objects, name the property to sort by.

1
2
{{ colours | sort | join: ", " }}                          # blue, green, purple, red, yellow
{{ people | sort: "age" | map: "name" | join: ", " }}      # Ben, David, April, Chloe

For descending order, add reverse:

1
{{ people | sort: "age" | reverse | map: "name" | join: ", " }}   # Chloe, April, David, Ben
  • Case-sensitive .
  • Capital letters sort before lower-case ones: use sort_natural to ignore case.
  • Numbers made with split are text, so they sort alphabetically. "10,9,100" | split: "," sorts as 10, 100, 9.
  • Empty values (nil) sort to the end.

sort_natural

Syntax: array | sort_natural or array | sort_natural: property

Like sort, but ignores upper and lower case.

1
2
3
{% assign words = "apple,Banana,cherry" | split: "," %}
{{ words | sort | join: ", " }}           # Banana, apple, cherry
{{ words | sort_natural | join: ", " }}   # apple, Banana, cherry

reverse

Syntax: array | reverse

Reverses the order of the items.

1
{{ colours | reverse | join: ", " }}   # purple, yellow, blue, green, red

In a for loop, the option is spelled reversed.

uniq

Syntax: array | uniq or array | uniq: property

Removes duplicates, keeping the first of each. For objects, name the property that decides whether two items count as the same.

1
{{ people | map: "team" | uniq | join: ", " }}   # red, blue

compact

Syntax: array | compact or array | compact: property

Removes empty (nil) items. With a property name, it removes the items whose property is nil.

If every person has a nickname property, but it is empty for some of them:

1
{{ people | map: "nickname" | compact | join: ", " }}

This lists only the nicknames that exist, without blank gaps.


Combining and transforming

map

Syntax: array | map: property

Builds a new array containing one property from each item.

1
{{ people | map: "name" | join: ", " }}   # April, Ben, Chloe, David

map is how you turn an array of objects into something you can print or total: follow it with join, sum, uniq or sort.

concat

Syntax: array | concat: other_array

Joins two arrays end to end. It doesn’t remove duplicates; use uniq.

If extra is an array holding pink and red:

1
2
{{ colours | concat: extra | join: ", " }}           # red, green, blue, yellow, purple, pink, red
{{ colours | concat: extra | uniq | join: ", " }}    # red, green, blue, yellow, purple, pink

Turning into text or a total

join

Syntax: array | join: separator

Joins the items into one string, with separator between them. Separator defaults to a space.

1
2
3
{{ colours | join: ", " }}   # red, green, blue, yellow, purple
{{ colours | join }}         # red green blue yellow purple
{{ colours | join: "" }}     # redgreenblueyellowpurple

sum

Syntax: array | sum or array | sum: property

Adds up the numbers in an array, or the numbers in one property of each item. An empty array gives 0. Text that looks like a number is converted.

1
{{ people | sum: "age" }}   # 124

size

Syntax: array | size

Counts the items.

1
{{ colours | size }}   # 5

Examples

A list of one property from the items that match:

1
{{ people | where: "team", "red" | map: "name" | join: ", " }}
1
April, Chloe

Count how many items match:

1
2
{% assign reds = people | where: "team", "red" %}
{{ reds.size }} people are in the red team.

Use a found item safely:

1
2
{% assign oldest = people | sort: "age" | last %}
{% if oldest %}The oldest person is {{ oldest.name }}.{% endif %}

Show a total of one property:

1
Total age: {{ people | sum: "age" }}

Dates

date

Can be applied to dates, text in a standard date layout, such as 2026-03-05, the words now or today**, which mean the current date and time when the template is shown. Note that a date formatted with eight digits is not read as a date: 20261111 is treated as a number of seconds, and comes out as August 1970.

Syntax: date | date: format

format is a string in which codes, each starting with %, stand for parts of the date.

1
2
3
4
5
6
7
{{ "2026-03-05 14:30:00" | date: "%d/%m/%Y" }}        # 05/03/2026
{{ "2026-03-05 14:30:00" | date: "%-d %B %Y" }}       # 5 March 2026
{{ "2026-03-05 14:30:00" | date: "%A %-d %B %Y" }}    # Thursday 5 March 2026
{{ "2026-03-05 14:30:00" | date: "%B %Y" }}           # March 2026
{{ "2026-03-05 14:30:00" | date: "%Y-%m-%d" }}        # 2026-03-05
{{ "2026-03-05 14:30:00" | date: "%H:%M" }}           # 14:30
{{ "2026-03-05 14:30:00" | date: "%-I:%M %p" }}       # 2:30 PM

Format codes

The examples in the last column are for 5 March 2026, 2:30 pm.

Code Meaning Example
%Y Year, four digits 2026
%y Year, two digits 26
%m Month number, two digits 03
%B Month name in full March
%b Month name, abbreviated Mar
%d Day of the month, two digits 05
%A Day of the week in full Thursday
%a Day of the week, abbreviated Thu
%j Day of the year 064
%H Hour, 24-hour clock 14
%I Hour, 12-hour clock 02
%M Minutes 30
%S Seconds 00
%p AM or PM PM
%P am or pm pm
%Z Time zone name for example GMT
%s Seconds since 1 January 1970 a large number
%% A percent sign %

Modifiers

Modifiers can be put between the % and the letter:

  • - removes the leading zero: %-d gives 5 instead of 05, and %-m and %-I work the same way.
  • ^ makes the result capitals: %^B gives MARCH.

Examples

Compare a date with today (is this still to come?). Dates can’t be compared directly, so turn each one into a number of seconds first:

1
2
3
{% assign when = date_value | date: "%s" | plus: 0 %}
{% assign right_now = "now" | date: "%s" | plus: 0 %}
{% if when > right_now %}Forthcoming{% else %}Published{% endif %}

A date with no time of day counts as the start of that day, so a product whose publication date is today counts as already published.