{{ -17 | abs }}Output
17Input
{{ 4 | abs }}Output
4abs will also work on a string that only contains a number:
{{ "-19.86" | abs }}Output
19.86
{{ "/my/fancy/url" | append: ".html" }}Output
/my/fancy/url.htmlappend can also be used with variables:
{% assign filename = "/index.html" %} {{ "website.com" | append: filename }}Output
website.com/index.html
{{ "foo,bar,baz" | split: "," | array_to_sentence_string }}Output
foo, bar, and bazInput
{{ "foo,bar,baz" | split: "," | array_to_sentence_string: "or" }}Output
foo, bar, or baz
{{ 4 | at_least: 5 }}Output
5Input
{{ 4 | at_least: 3 }}Output
4
{{ 4 | at_most: 5 }}Output
4Input
{{ 4 | at_most: 3 }}Output
3
{{ "title" | capitalize }}Output
Titlecapitalize only capitalizes the first character of a string, so later words are not affected:
{{ "my great title" | capitalize }}Output
My great title
{{ 1.2 | ceil }}Output
2Input
{{ 2.0 | ceil }}Output
2Input
{{ 183.357 | ceil }}Output
184Here the input value is a string: Input
{{ "3.5" | ceil }}Output
4
{{ "foo, bar; baz?" | cgi_escape }}Output
foo%2C+bar%3B+baz%3F
{% assign site_categories = site.pages | map: "category" %} {% for category in site_categories %} - {{ category }} {% endfor %}Output
- business - celebrities - - lifestyle - sports - - technologyBy using compact when we create our site_categories array, we can remove all the nil values in the array.
{% assign site_categories = site.pages | map: "category" | compact %} {% for category in site_categories %} - {{ category }} {% endfor %}Output
- business - celebrities - lifestyle - sports - technology
{% assign fruits = "apples, oranges, peaches" | split: ", " %} {% assign vegetables = "carrots, turnips, potatoes" | split: ", " %} {% assign everything = fruits | concat: vegetables %} {% for item in everything %} - {{ item }} {% endfor %}Output
- apples - oranges - peaches - carrots - turnips - potatoesYou can string together concat filters to join more than two arrays:
{% assign furniture = "chairs, tables, shelves" | split: ", " %} {% assign everything = fruits | concat: vegetables | concat: furniture %} {% for item in everything %} - {{ item }} {% endfor %}Output
- apples - oranges - peaches - carrots - turnips - potatoes - chairs - tables - shelves
{{ article.published_at | date: '%a, %b %d, %y' }} => Fri, Jul 17, 15 {{ "now" | date: "%Y-%m-%d %H:%M" }} => 2020-03-25 15:57 // equivalent to setting options.dateFormat = %d%q of %b %Y at %I:%M %P %Z {{ '1990-12-31T23:30:28Z' | date: '%d%q of %b %Y at %I:%M %P %Z', -330 }} => 01st of Jan 1991 at 05:00 am +0530;TimeZone During output, Liquid uses local timezone which can override by: setting a timezone in-place when calling date filter, or setting the Liquid option It defaults to runtime’s time one. Offset can be set as, minutes: -360 means '+06:00' and 360 means '-06:00' timeZone ID: Asia/Colombo or America/New_York See for TZ database values
// equivalent to setting `options.timezoneOffset` to `360` {{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", 360 }} => 1990-12-31T17:00:00 {{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", "Asia/Colombo" }} => 1991-01-01T04:30:00Input date works on strings if they contain well-formatted dates Note that Liquid is using to parse the input string, that means and strings in are supported.
{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", 360 }} => 1990-12-31T17:00:00 {{ "March 14, 2016" | date: "%b %d, %y" }} => Mar 14, 16Current Date To get the current time, pass the special word "now" or "today" as input Note that the value will be the current time of when the page was last generated from the template, not when the page is presented to a user if caching or static site generation is involved Example
Last updated on: {{ "now" | date: "%Y-%m-%d %H:%M" }} => Last updated on: 2020-03-25 15:57 Last updated on: {{ "today" | date: "%Y-%m-%d %H:%M" }} => Last updated on: 2020-03-25 15:57
{{ site.time | date_to_long_string }}Output
07 November 2008Input
{{ site.time | date_to_long_string: "ordinal" }}Output
7th November 2008Note that JavaScript Date has not timezone information, see filter for details.
{{ site.time | date_to_rfc822 }}Output
Mon, 07 Nov 2008 13:07:54 -0800Note that JavaScript Date has not timezone information, see filter for details.
{{ site.time | date_to_string }}Output
07 Nov 2008Input
{{ site.time | date_to_string: "ordinal", "US" }}Output
Nov 7th, 2008Note that JavaScript Date has not timezone information, see filter for details.
{{ site.time | date_to_xmlschema }}Output
2008-11-07T13:07:54-08:00Note that JavaScript Date has not timezone information, see filter for details.
{{ product_price | default: 2.99 }}Output
2.99In this example, product_price is defined, so the default value is not used.
{% assign product_price = 4.99 %} {{ product_price | default: 2.99 }}Output
4.99In this example, product_price is empty, so the default value is used.
{% assign product_price = "" %} {{ product_price | default: 2.99 }}Output
2.99
{% assign display_price = false %} {{ display_price | default: true, allow_false: true }}Output
false
{{ 16 | divided_by: 4 }}Output
4Input
{{ 5 | divided_by: 3 }}Output
1.6666666666666667In JavaScript, float and integer shares the same type number and we cannot tell the difference.
// always true 5.0 === 5You’ll need to pass another integerArithmetic argument to enforce integer divide:
{{ 5 | divided_by: 3, true }}Output
1
{{ "Parker Moore" | downcase }}Output
parker mooreInput
{{ "apple" | downcase }}Output
apple
{{ "Have you read 'James & the Giant Peach'?" | escape }}Output
Have you read 'James & the Giant Peach'?Input
{{ "Tetsuro Takara" | escape }}Output
Tetsuro Takara
{{ "1 < 2 & 3" | escape_once }}Output
1 < 2 & 3Input
{{ "1 < 2 & 3" | escape_once }}Output
1 < 2 & 3
const members = [ { graduation_year: 2013, name: 'Jay' }, { graduation_year: 2014, name: 'John' }, { graduation_year: 2014, name: 'Jack' } ]Input
{{ members | find: "graduation_year", 2014 | json }}Output
{"graduation_year":2014,"name":"John"}
const members = [ { graduation_year: 2013, name: 'Jay' }, { graduation_year: 2014, name: 'John' }, { graduation_year: 2014, name: 'Jack' } ]Input
{{ members | find_exp: "item", "item.graduation_year == 2014" | json }}Output
{"graduation_year":2014,"name":"John"}
{{ "Ground control to Major Tom." | split: " " | first }}Output
GroundInput
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} {{ my_array.first }}Output
zebraYou can use first with dot notation when you need to use the filter inside a tag:
{% if my_array.first == "zebra" %} Here comes a zebra! {% endif %}
{{ 1.2 | floor }}Output
1Input
{{ 2.0 | floor }}Output
2Input
{{ 183.357 | floor }}Output
183Here the input value is a string: Input
{{ "3.5" | floor }}Output
3
const members = [ { graduation_year: 2003, name: 'Jay' }, { graduation_year: 2003, name: 'John' }, { graduation_year: 2004, name: 'Jack' } ]Input
{{ members | group_by: "graduation_year" | json: 2 }}Output
[ { "name": 2003, "items": [ { "graduation_year": 2003, "name": "Jay" }, { "graduation_year": 2003, "name": "John" } ] }, { "name": 2004, "items": [ { "graduation_year": 2004, "name": "Jack" } ] } ]
const members = [ { graduation_year: 2013, name: 'Jay' }, { graduation_year: 2014, name: 'John' }, { graduation_year: 2009, name: 'Jack' } ]Input
{{ members | group_by_exp: "item", "item.graduation_year | truncate: 3, ''" | json: 2 }}Output
[ { "name": "201", "items": [ { "graduation_year": 2013, "name": "Jay" }, { "graduation_year": 2014, "name": "John" } ] }, { "name": "200", "items": [ { "graduation_year": 2009, "name": "Jack" } ] } ]
const foo = { bar: 'BAR' } foo.foo = foo const scope = { foo }Input
{% foo | inspect %}Output
{"bar":"BAR","foo":"[Circular]"}
{{ foo | inspect: 4 }}Output
{ "bar": "BAR", "foo": "[Circular]" }
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {{ beatles | join: " and " }}Output
John and Paul and George and Ringo
{% assign arr = "foo bar coo" | split: " " %} {{ arr | json }}Output
["foo","bar","coo"]
{% assign arr = "foo bar coo" | split: " " %} {{ arr | json: 4 }}Output
[ "foo", "bar", "coo" ]
{{ "Ground control to Major Tom." | split: " " | last }}Output
Tom.Input
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %} {{ my_array.last }}Output
tigerYou can use last with dot notation when you need to use the filter inside a tag:
{% if my_array.last == "tiger" %} There goes a tiger! {% endif %}
BEGIN{{ " So much room for activities! " | lstrip }}ENDOutput
BEGINSo much room for activities! END
{% assign all_categories = site.pages | map: "category" %} {% for item in all_categories %} - {{ item }} {% endfor %}Output
- business - celebrities - lifestyle - sports - technology
{{ 4 | minus: 2 }}Output
2Input
{{ 16 | minus: 4 }}Output
12Input
{{ 183.357 | minus: 12 }}Output
171.357
{{ 3 | modulo: 2 }}Output
1Input
{{ 24 | modulo: 7 }}Output
3Input
{{ 183.357 | modulo: 12 }}Output
3.3569999999999993
{% capture string_with_newlines %} Hello there {% endcapture %} {{ string_with_newlines | newline_to_br }}Output
<br/>Hello<br/>there<br/>
{{ "a \n b" | normalize_whitespace }}Output
a b
{{ "Hello world!" | number_of_words }}Output
2Input
{{ "你好hello世界world" | number_of_words }}Output
1Input
{{ "你好hello世界world" | number_of_words: "cjk" }}Output
6Input
{{ "你好hello世界world" | number_of_words: "auto" }}Output
6
{{ 4 | plus: 2 }}Output
6Input
{{ 16 | plus: 4 }}Output
20Input
{{ 183.357 | plus: 12 }}Output
195.357
{% assign fruits = "apples, oranges, peaches" | split: ", " %} {% assign everything = fruits | pop %} {% for item in everything %} - {{ item }} {% endfor %}Output
- apples - oranges
{% assign fruits = "apples, oranges" | split: ", " %} {% assign everything = fruits | push: "peaches" %} {% for item in everything %} - {{ item }} {% endfor %}Output
- apples - oranges - peaches
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}Output
Some fruit: apples, oranges, and bananasprepend can also be used with variables: Input
{% assign url = "example.com" %} {{ "/index.html" | prepend: url }}Output
example.com/index.html
{{ "<" }}Output
<Input (outputEscape="escape")
{{ "<" }}Output
<Input (outputEscape="json")
{{ "<" }}Output
"<"Input (outputEscape="escape")
{{ "<" | raw }}Output
<
{{ "I strained to see the train through the rain" | remove: "rain" }}Output
I sted to see the t through the
{{ "I strained to see the train through the rain" | remove_first: "rain" }}Output
I sted to see the train through the rain
{{ "I strained to see the train through the rain" | remove_last: "rain" }}Output
I strained to see the train through the
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}Output
Take your protein pills and put your helmet on
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}Output
Take your protein pills and put my helmet on
{{ "Take my protein pills and put my helmet on" | replace_last: "my", "your" }}Output
Take my protein pills and put your helmet on
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ my_array | reverse | join: ", " }}Output
plums, peaches, oranges, applesAlthough reverse cannot be used directly on a string, you can split a string into an array, reverse the array, and rejoin it by chaining together filters:
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}Output
.moT rojaM ot lortnoc dnuorG
{{ 1.2 | round }}Output
1Input
{{ 2.7 | round }}Output
3Input
{{ 183.357 | round: 2 }}Output
183.36
BEGIN{{ " So much room for activities! " | rstrip }}ENDOutput
BEGIN So much room for activities!END
{% assign fruits = "apples, oranges, peaches" | split: ", " %} {% assign everything = fruits | shift %} {% for item in everything %} - {{ item }} {% endfor %}Output
- oranges - peaches
{{ "Ground control to Major Tom." | size }}Output
28Input
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %} {{ my_array.size }}Output
4You can use size with dot notation when you need to use the filter inside a tag:
{% if site.pages.size > 10 %} This is a big website! {% endif %}
{{ "WISMOlabs liquid" | slice: 0 }}Output
LInput
{{ "WISMOlabs liquid" | slice: 2 }}Output
qInput
{{ "WISMOlabs liquid" | slice: 2, 5 }}Output
quidIf the first argument is a negative number, the indices are counted from the end of the string:
{{ "WISMOlabs liquid" | slice: -3, 2 }}Output
ui
{{ "The _config.yml file" | slugify }}Output
the-config-yml-fileInput
{{ "The _config.yml file" | slugify: "pretty" }}Output
the-_config.yml-fileInput
{{ "The _cönfig.yml file" | slugify: "ascii" }}Output
the-c-nfig-yml-fileInput
{{ "The cönfig.yml file" | slugify: "latin" }}Output
the-config-yml-fileInput
{{ "The cönfig.yml file" | slugify: "latin", true }}Output
The-config-yml-file
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} {{ my_array | sort | join: ", " }}Output
Sally Snake, giraffe, octopus, zebraAn optional argument specifies which property of the array’s items to use for sorting.
{% assign products_by_price = collection.products | sort: "price" %} {% for product in products_by_price %} <h4>{{ product.title }}</h4> {% endfor %}
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} {{ my_array | sort_natural | join: ", " }}Output
giraffe, octopus, Sally Snake, zebraAn optional argument specifies which property of the array’s items to use for sorting.
{% assign products_by_company = collection.products | sort_natural: "company" %} {% for product in products_by_company %} <h4>{{ product.title }}</h4> {% endfor %}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {% for member in beatles %} {{ member }} {% endfor %}Output
John Paul George Ringo
BEGIN{{ " So much room for activities! " | strip }}ENDOutput
BEGINSo much room for activities!END
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}Output
Have you read Ulysses?
{% capture string_with_newlines %} Hello there {% endcapture %} {{ string_with_newlines | strip_newlines }}Output
Hellothere
The cart has {{ order.products | sum: "qty" }} products.Output
The cart has 7 products.
{{ 3 | times: 2 }}Output
6Input
{{ 24 | times: 7 }}Output
168Input
{{ 183.357 | times: 12 }}Output
2200.284
{{ "123" | to_integer | json }}Output
123
{{ "Ground control to Major Tom." | truncate: 20 }}Output
Ground control to...
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}Output
Ground control, and so on
{{ "Ground control to Major Tom." | truncate: 20, "" }}Output
Ground control to Ma
{{ "Ground control to Major Tom." | truncatewords: 3 }}Output
Ground control to...Custom ellipsistruncatewords takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (…), but you can specify a different sequence.
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}Output
Ground control to--No ellipsisYou can avoid showing trailing characters by passing a blank string as the second argument:
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}Output
Ground control to
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %} {{ my_array | uniq | join: ", " }}Output
ants, bugs, bees
{% assign fruits = "oranges, peaches" | split: ", " %} {% assign everything = fruits | unshift: "apples" %} {% for item in everything %} - {{ item }} {% endfor %}Output
- apples - oranges - peaches
{{ "Parker Moore" | upcase }}Output
PARKER MOOREInput
{{ "APPLE" | upcase }}Output
APPLE
{{ "https://example.com/?q=foo, \bar?" | uri_escape }}Output
https://example.com/?q=foo,%20%5Cbar?
{{ "%27Stop%21%27+said+Fred" | url_decode }}Output
'Stop!' said Fred
{{ "john@liquid.com" | url_encode }}Output
john%40liquid.comInput
{{ "Tetsuro Takara" | url_encode }}Output
Tetsuro+Takara
All products: {% for product in products %} - {{ product.title }} {% endfor %} {% assign kitchen_products = products | where: "type", "kitchen" %} Kitchen products: {% for product in kitchen_products %} - {{ product.title }} {% endfor %}Output
All products: - Vacuum - Spatula - Television - Garlic press Kitchen products: - Spatula - Garlic pressSay instead you have a list of products and you only want to show those that are available to buy. You can where with a property name but no target value to include all products with a "available" value.
All products: {% for product in products %} - {{ product.title }} {% endfor %} {% assign available_products = products | where: "available" %} Available products: {% for product in available_products %} - {{ product.title }} {% endfor %}Output
All products: - Coffee mug - Limited edition sneakers - Boring sneakers Available products: - Coffee mug - Boring sneakersThe where filter can also be used to find a single object in an array when combined with the first filter. For example, say you want to show off the shirt in your new fall collection.
{% assign new_shirt = products | where: "type", "shirt" | first %} Featured product: {{ new_shirt.title }}Output
Featured product: Hawaiian print sweater vestAdditionally, property can be any valid Liquid variable expression as used in output syntax, except that the scope of this expression is within each item.
const products = [ { meta: { details: { class: 'A' } }, order: 1 }, { meta: { details: { class: 'B' } }, order: 2 }, { meta: { details: { class: 'B' } }, order: 3 } ]Input
{% assign selected = products | where: 'meta.details["class"]', "B" %} {% for item in selected -%} - {{ item.order }} {% endfor %}Output
- 2 - 3
All products: {% for product in products %} - {{ product.title }} {% endfor %} {% assign kitchen_products = products | where_exp: "item", "item.type == 'kitchen'" %} Kitchen products: {% for product in kitchen_products %} - {{ product.title }} {% endfor %}Output
All products: - Vacuum - Spatula - Television - Garlic press Kitchen products: - Spatula - Garlic press
{{ "Have you read \'James & the Giant Peach\'?" | xml_escape }}Output
Have you read 'James & the Giant Peach'?