All filters
Grouped by functionality.
This is a based info on the CloudCannon Jekyll cheatsheet. See also Liquid filters on Jekyll docs.
The items here are grouped and ordered by use, rather than alpabetically.
For escaping a URI:
url_escapecgi_escape
For escaping HTML tags:
xml_escapeescapeescape_once
See also the Arrays cheatsheet.
String filters
-
append{{ 'jekyll' | append: '.jpg' }} -
prepend{{ 'Jekyll' | prepend: 'I love ' }} -
sliceGet items in an iterable from start index (inclusive) for a limit of items. See also
slicein Array section and belowoffsetandlimitin the For loops page.{{ "hello" | slice: 0 }} <!-- h --> {{ "hello" | slice: 1 }} <!-- e --> {{ "hello" | slice: 2, 3 }} <!-- ell --> -
markdownify -
jsonify{{ my_var | jsonify }} {{ site.data.my_data | jsonify }} -
inspectShow a value as a Ruby object. Useful for debugging. Especially useful if a value is possibly null and therefore invisible or if you have a data structure to understand.
{{ my_var | inspect }} {{ site.page | inspect }} -
date -
default{% assign new_var = foo | default: 'fallback' %} {% assign new_var = bar.buzz | default: 'fallback' %} -
replaceWarning - if you do
replaceon an array, it converts it to a string. -
replace_first -
strip -
lstrip -
rstrip -
capitalize -
downcase -
upcase -
split{{ my_str | split: ',' }} -
truncateTruncate a string down to x characters
-
truncatewordsTruncate a string down to x words
-
strip_html -
strip_newlinesRemove
\ncharacters -
newline_to_brConvert
\nto twobrtags -
escapeEscape HTML so that tags appear as ampersand charactes that aren’t evaluated
{{ "<p>Jekyll</p>" | escape }} Result: &lt;p&gt;Jekyll&lt;/p&gt; -
uri_escapeEscape a URI with percent coding
{{ "foo, bar \baz?" | uri_escape }} Result: foo,%20bar%20%5Cbaz? -
url_decode -
url_encode -
slugify{{ "The _config.yml file" | slugify }} <!-- the-config-yml-file -->
Array filters
-
join{{ my_array | join: ', ' }} -
first{{ my_array | first }} -
last{{ my_array | last }} -
concatCombine to arrays - parameter must be of type array to avoid error
--- foo: - abc - def bar: - 123 --- {{ page.foo | concat: page.bar | inspect }} -
sliceGet an item by index. Or with two values as a range, set a start index and a count of elements. See also
offsetandlimiton the For loops page.--- foo: ['abc', 'def', 'ghi', 'jkl', 'mno' ] --- {{ page.foo | slice: 0 }} <!-- 1st element --> {{ page.foo | slice: 3 }} <!-- 4th element --> {{ page.foo | slice: 0, 3 }} <!-- First three elements --> {{ page.foo | slice: 1, 3 }} <!-- First 3 elements starting at 2nd element --> -
map{{ my_array | map: "some_attribute" }} -
whereA simple filter where an attribute value matches a given value.
{{ site.posts | where: "category", "foo" }} {{ page.people | where: "school", "Stanford" }} -
where_expA filter where a given expression is true.
{{ page.people | where_exp: "item", "item.name contains 'Jo'" }} {{ page.people | where_exp: "item", "item.year >= 2016" }} {{ page.people | where_exp: "item", "item.school != "Stanford" }} -
group_byGroup an array’s items by a given property. You’ll get a hash where that attribute is used as the key and the value is all the match items (the attribute is not removed).
{{ page.people | group_by: country }} <!-- Source: [ [name: 'Joe', country: 'England'], [name: 'Sally', country: 'England'] Result: { England: [ [name: 'Joe', country: 'England'], [name: 'Sally', country: 'England'] ] } --> -
group_by_exp{{ page.people | group_by_exp: "item", "item.name | size" }} {{ page.people | group_by_exp: "item", "item.year | modulo: 2" }} {{ page.people | group_by_exp: "item", "item.country | replace: 'rd', 'ry' " }} -
size{{ my_array | size }} -
reverse{{ my_array | reverse }} -
sort{{ my_array | sort }} {{ page.posts | sort: 'author' }} -
sort_naturalSorts items in an array in case-insensitive order
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %} {{ my_array | sort_natural | join: ", " }} -
uniqYou don’t have to sort, but if you do then your results will read better.
{{ my_array | uniq }} {{ my_array | sort | uniq }} -
pushInsert at the end of the array
{% assign my_array = my_array | push: 'my value ' %} -
popRemove an item from the end of an array. Accepts optional param
numwhich defaults to1{% assign value = my_array | pop %} {% assign value = my_array | pop: 1 %} -
unshiftInsert at the start of the array
{% assign my_array = my_array | unshift: 'my value ' %} -
shiftRemove an item from the start of an array. Accepts optional param
numwhich defaults to1{% assign value = my_array | shift %} {% assign value = my_array | shift: 1 %} -
compactRemoves any nil values from an array.
{% assign site_categories = site.pages | map: "category" | compact %}
Maths
-
plus{{ 4 | plus: 2 }} -
minus -
times -
divided_by -
modulo -
floor -
ceil -
round -
abs -
at_leastLimits a number to a minimum value. Same as
min(a, b)in other languages.{{ 4 | at_least: 3 }} <!-- 3 -- > -
at_mostLimits a number to a maximum value. Same as
max(a, b)in other languages.