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_escape
  • cgi_escape

For escaping HTML tags:

  • xml_escape
  • escape
  • escape_once

See also the Arrays cheatsheet.

String filters

  • append
    {{ 'jekyll' | append: '.jpg' }}
  • prepend
    {{ 'Jekyll' | prepend: 'I love ' }}
  • slice

    Get items in an iterable from start index (inclusive) for a limit of items. See also slice in Array section and below offset and limit in 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 }}
  • inspect

    Show 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' %}
  • replace

    Warning - if you do replace on an array, it converts it to a string.

  • replace_first
  • strip
  • lstrip
  • rstrip
  • capitalize
  • downcase
  • upcase
  • split
    {{ my_str | split: ',' }}
  • truncate

    Truncate a string down to x characters

  • truncatewords

    Truncate a string down to x words

  • strip_html
  • strip_newlines

    Remove \n characters

  • newline_to_br

    Convert \n to two br tags

  • escape

    Escape HTML so that tags appear as ampersand charactes that aren’t evaluated

    {{ "<p>Jekyll</p>" | escape }}
    
    Result:
    
    &amp;lt;p&amp;gt;Jekyll&amp;lt;/p&amp;gt;
  • uri_escape

    Escape 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 }}
  • concat

    Combine to arrays - parameter must be of type array to avoid error

    ---
    foo:
      - abc
      - def
    bar:
      - 123
    ---
    {{ page.foo | concat: page.bar | inspect }}
  • slice

    Get an item by index. Or with two values as a range, set a start index and a count of elements. See also offset and limit on 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" }}
  • where

    A simple filter where an attribute value matches a given value.

    {{ site.posts | where: "category", "foo" }}
    {{ page.people | where: "school", "Stanford" }}
  • where_exp

    A 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_by

    Group 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_natural

    Sorts items in an array in case-insensitive order

    {% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
    {{ my_array | sort_natural | join: ", " }}
  • uniq

    You don’t have to sort, but if you do then your results will read better.

    {{ my_array | uniq }}
    {{ my_array | sort | uniq }}
  • push

    Insert at the end of the array

    {% assign my_array = my_array | push: 'my value ' %}
  • pop

    Remove an item from the end of an array. Accepts optional param num which defaults to 1

    {% assign value = my_array | pop %}
    {% assign value = my_array | pop: 1 %}
  • unshift

    Insert at the start of the array

    {% assign my_array = my_array | unshift: 'my value ' %}
  • shift

    Remove an item from the start of an array. Accepts optional param num which defaults to 1

    {% assign value = my_array | shift %}
    {% assign value = my_array | shift: 1 %}
  • compact

    Removes 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_least

    Limits a number to a minimum value. Same as min(a, b) in other languages.

    {{ 4 | at_least: 3 }} <!-- 3 -- >
  • at_most

    Limits a number to a maximum value. Same as max(a, b) in other languages.