Skip to content
On this page · 13 sections
  1. Escaping
  2. Text
  3. Numbers
  4. Lists
  5. Money and dates
  6. URLs and assets
  7. Images and media
  8. HTML and content
  9. Translations
  10. Colours
  11. Fonts
  12. Data
  13. Tag links
Docs

Liquid filters

Updated

The Liquid filters in1s themes can use, grouped by purpose: text, numbers, lists, money, dates, URLs and assets, images and media, HTML, colours, fonts, translations and data.

Filters change a value before it is printed or assigned: {{ entry.title | upcase }}. They run from left to right, and many take arguments after a colon: {{ text | truncate: 120 }}.

Important: A filter's argument takes no filters

In {{ a | default: b | upcase }} the upcase applies to the whole result, not to b. When an argument needs its own filter, assign it first:

{%- assign fallback = settings.tagline | upcase -%}
{{ section.settings.heading | default: fallback }}

Warning: Unknown filters fail silently

On a page, a filter name the engine does not know passes its input through unchanged, with no error. The code editor's Problems panel flags unknown filters, so check it when output looks unfiltered.

Escaping

Liquid prints values as they are. Escape text you print into HTML, and always escape anything a visitor typed (search.terms, form.session values, submissions).

Filter What it does
escape Escapes <, >, & and quotes, for text and attribute values
escape_once Escapes, without escaping entities that are already escaped
url_encode, url_escape, url_param_escape Encode text for use in a URL
strip_html Removes tags. The result is plain text that may contain < again, so escape it too: {{ x | strip_html | escape }}
sanitize_html Keeps a safe set of HTML tags and attributes and removes the rest

For a number from untrusted input, use | times: 1, which turns anything that is not a number into 0.

Text

Filter Example Result
append, prepend {{ 'file' | append: '.pdf' }} file.pdf
upcase, downcase, capitalize {{ 'hello' | capitalize }} Hello
camelcase {{ 'my title' | camelcase }} camelCase
handle, handleize {{ 'Hello World' | handle }} hello-world
replace, replace_first {{ 'a-b-c' | replace: '-', ' ' }} a b c
remove, remove_first {{ 'a-b' | remove: '-' }} ab
strip, lstrip, rstrip Remove whitespace at both ends, the start or the end
strip_newlines, newline_to_br Remove line breaks, or turn them into <br>
truncate {{ text | truncate: 20 }} Cut to 20 characters, ending in ...
truncatewords {{ text | truncatewords: 10 }} Cut to 10 words
split {{ 'a,b' | split: ',' }} A list
slice {{ 'hello' | slice: 1, 3 }} ell (also works on lists)
pluralize {{ count | pluralize: 'item', 'items' }} item for 1, items otherwise
md5, sha1, sha256 A hash of the text
hmac_sha1, hmac_sha256 {{ text | hmac_sha256: 'secret' }} A keyed hash
string The value as text
raw The value unchanged

Numbers

Filter Example Result
plus, minus, times, divided_by {{ 10 | divided_by: 4 }} 2 (two whole numbers give a whole number; write 4.0 for 2.5)
modulo {{ 7 | modulo: 3 }} 1
round {{ 3.14159 | round: 2 }} 3.14
ceil, floor {{ 3.2 | ceil }} 4
abs {{ -5 | abs }} 5
at_least, at_most {{ n | at_most: 100 }} Keep a number within a bound

Text that is not a number counts as 0. Dividing by zero gives 0 rather than an error.

A decimal number that is whole keeps its point, as in Shopify: {{ 4 | times: 1.0 | round: 1 }} prints 4.0. Use round with no digits to print a whole number.

Lists

Filter Example
size {{ data_list.entries | size }}
first, last {{ entries | first }} (nothing when the list is empty)
join {{ tags | join: ', ' }}
map {{ entries | map: 'title' }}
where {{ entries | where: 'featured', true }}; with one argument, keeps items whose value is true
sort, sort_key {{ entries | sort: 'title' }}
uniq {{ list | uniq }} or {{ entries | uniq: 'author' }}
reverse {{ list | reverse }}
concat {{ list_a | concat: list_b }}
sum {{ numbers | sum }}
json {{ value | json }}, for scripts and JSON-LD

where compares exactly: 1 and "1" are different.

Money and dates

money
Formats a number as a price using the theme's currency settings: {{ price | money }}. You can pass a symbol and its position: {{ price | money: '€', 'after' }}. A value that is not a number is returned unchanged, so escape untrusted input first: {{ price | escape | money }}.
money_without_trailing_zeros
The same, without .00.
date
Formats a date with strftime codes: {{ entry.published_at | date: '%B %d, %Y' }}. A number is read as a Unix timestamp.
time_tag
Prints a <time> element with a formatted date: {{ entry.published_at | time_tag: '%d %b %Y' }}.

URLs and assets

Filter What it gives
asset_url The URL of a file in your theme's assets/ folder: {{ 'base.css' | asset_url }}. The URL changes when the file changes, so never add a ?v= yourself.
asset_img_url, file_url, file_img_url The URL of a theme asset, like asset_url
stylesheet_tag A <link rel="stylesheet">: {{ 'base.css' | asset_url | stylesheet_tag }}
script_tag A <script> tag for a URL
in1s_asset_url The URL of a file the platform provides for all themes
route_url One of your site's paths in the visitor's language: {{ '/about' | route_url }}. Always use it for internal links, so visitors stay in their language. Links starting with http, https, mailto:, tel:, // or # are kept as written.
link_to An <a> tag: {{ 'Contact' | link_to: '/contact' }}
sort_by A listing URL with a sort applied: {{ data_list.url | sort_by: 'title-ascending' }}
within Accepted for Shopify compatibility; returns the URL unchanged

global_asset_url and shopify_asset_url are older names for in1s_asset_url.

Images and media

image_url
The URL of an image, with optional size parameters: {{ section.settings.image | image_url: width: 800 }}. Takes an image setting, an image field or a URL. Returns nothing for an empty image.
image_tag
An <img> element for an image URL. widths builds a srcset, sizes goes with it, and any other argument becomes an attribute. With neither width nor height, an image of known size gets its size, so the page does not shift while it loads.
{{ section.settings.image | image_url: width: 1600 | image_tag: widths: '400,800,1200,1600', sizes: '100vw', alt: section.settings.image.alt, loading: 'lazy' }}
img_url
Shopify's older image filter, with a WIDTHxHEIGHT size: {{ image | img_url: '600x' }}.
media_tag
A <video> element for an uploaded video (from a video setting or field), or an <img> for an image. Extra arguments become attributes: {{ section.settings.video | media_tag: controls: true }}.
external_video_tag
An <iframe> player for a YouTube or Vimeo link (from a video_url setting or field). Extra arguments become attributes: {{ section.settings.video_url | external_video_tag: class: 'video' }}.
placeholder_svg_tag
A placeholder illustration as inline SVG, to show while an image is not set: {{ 'image' | placeholder_svg_tag }}.

HTML and content

markdown
Turns Markdown into HTML: headings, lists, links, tables, task lists, strikethrough, footnotes and description lists. Raw HTML in the input is escaped and unsafe links are removed, so the output is safe to print as it is. Do not escape it.
field_html
Prints an entry field as its type allows: rich text, HTML and textarea fields as stored, every other type escaped. Pass the value, then the entry and the field id: {{ entry.content | field_html: entry, 'content' }}.
option_label
Shows a select, radio or checkbox_group field's option label in the visitor's language instead of its stored value: {{ entry.status | option_label: entry, 'status' | escape }}.
default
A fallback for nil, false and empty values: {{ section.settings.heading | default: 'Welcome' }}. 0 and a space are kept as they are.
default_errors
Prints a form's errors as a list: {{ form.errors | default_errors }}. It escapes the messages itself.
default_pagination
Prints page links inside {% paginate %}: {{ paginate | default_pagination }}.

Translations

t
Looks a key up in the theme's locale files, in the visitor's language: {{ 'general.search' | t }}. Missing keys in a language fall back to the default locale file.
  • Values can take parameters: with "showing": "Page {{ number }}", write {{ 'general.showing' | t: number: 2 }}.
  • A key whose value has one and other forms (and the forms other languages need) picks one from count: {{ 'general.results' | t: count: search.results_count }}.
  • Output is escaped. A key whose name ends in _html is printed as HTML.

See Theme settings and translations.

Colours

Inputs can be hex (#rgb, #rrggbb, with or without alpha), rgb(), hsl() or a colour setting. A value that is not a colour passes through.

Filter Example
color_to_rgb, color_to_hsl, color_to_hex {{ settings.accent | color_to_rgb }}
color_extract {{ color | color_extract: 'red' }} (also green, blue, hue, saturation, lightness, alpha)
color_modify {{ color | color_modify: 'alpha', 0.5 }}
color_lighten, color_darken {{ color | color_darken: 10 }}
color_saturate, color_desaturate {{ color | color_saturate: 20 }}
color_mix {{ color | color_mix: '#ffffff', 50 }} (the number is the weight of the first colour)
color_brightness Perceived brightness, 0 to 255
color_contrast {{ text | color_contrast: background }}, the contrast ratio
color_difference, brightness_difference How different two colours are
rgb_to_hex, hsl_to_hex Convert to hex

Fonts

For a font_picker setting:

Filter What it gives
font_url The stylesheet URL for a built-in web font, or nothing for system and uploaded fonts. Use it in a <link>.
font_face The @font-face rule for an uploaded font, or nothing for other fonts. Use it inside {% style %}.
font_modify Another weight or style of the same family: {{ settings.font | font_modify: 'weight', 'bold' }}

Calling both font_url and font_face for every font setting covers every kind of font.

Data

submissions_for
The submissions of a form that point to an entry through a reference field, oldest first, only those the form shows on the site: {% assign reviews = entry | submissions_for: 'reviews' %}. Pass a number as a second argument for more than 50, up to 200. Visitors wrote these values: escape every one.
submissions_sum
The sum of a number field across a form's submissions: {{ 'orders' | submissions_sum: 'amount' }}.

link_to_tag, link_to_add_tag, link_to_remove_tag and tag_path build links for filtering a listing by tag. For filtering by a field, data_list.filters gives ready-made option URLs (see Liquid objects).

Start typing to search the docs.