Skip to content
Log in

Liquid Filters

On this page

Filters transform a value on its way into the page: formatting text, reshaping a collection, doing arithmetic. They are applied with a pipe, and can be chained.

```liquid

{{ product.name | upcase }} {{ products | pluck: “name” | json }} ```

Each filter below links to its own article with the full signature and worked examples. To read the whole set on one page instead, see the Liquid filters reference.

Collections

  • depaginate — Turns off the protective enforced pagination for large collections. Useful when needing to apply other filters to the paginated collection, eg where. Will trigger a full fetch of the entire collection when used, and could cause performance issues if the data set is large. Use carefully
  • group_by — Groups an list of objects by a given property
  • json — Converts the collection to JSON
  • paginate — Gets the first page of a Paginated collection with the supplied size
  • pluck — Plucks all values for a given property from an list
  • sample — Returns a random sample in random order of all the values for a given collection
  • serialize — Serializes the collection as a JSON string
  • sum — Sums all items in an list
  • try — Tries to call the supplied attribute against the supplied object. Use this when you know the property may or may not exist on the object as a way to indicate that it’s expected and ok for it not to exist

Lists

  • compact — Removes any nil values from an list
  • concat — Concatenates (joins together) multiple lists. The resulting list contains all the items from the input lists
  • contains — Returns true if the list contains the supplied item
  • difference — Returns the difference of two lists
  • except — Returns all items in the list where the supplied property does not equal the supplied value
  • first — Returns the first item of an list
  • insert — Inserts an item into an list at the supplied index
  • intersection — Returns the intersection of two lists
  • join — Combines the items in an list into a single string using the argument as a separator
  • last — Returns the last item of an list
  • map — Creates an list of values by extracting the values of a named property from another object
  • only — Returns all items in the list where the supplied property equals one of the supplied values
  • pop — Removes the last item from an list
  • push — Adds an item to the end of an list
  • reverse — Reverses the order of the items in an list. reverse cannot reverse a string
  • shift — Removes the first item from an list
  • size — Returns the number of characters in a string or the number of items in an list
  • sort — Sorts items in an list in case-sensitive order
  • sort_natural — Sorts items in an list in case-insensitive order
  • union — Returns the union of two lists
  • uniq — Removes any duplicate items in an list
  • unshift — Adds an item to the beginning of an list
  • where — Creates an list including only the objects with a given property value, or any truthy value by default

Maps

  • collect_keys — Plucks a set of values from a list of maps
  • keys — Returns a list of the keys of a Map
  • merge — Merges two maps together
  • rename_keys — Renames keys in a map
  • set_key — Sets a key in a map to a value
  • unset_key — Removes a key from a map

Numbers

  • abs — Returns the absolute value of a number
  • at_least — Limits a number to a minimum value
  • at_most — Limits a number to a maximum value
  • ceil — Rounds an input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied
  • divided_by — Divides a number by another number
  • floor — Rounds an input down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied
  • minus — Subtracts a number from another number
  • modulo — Returns the remainder of a division operation
  • money — Formats the input as money in the default currency
  • number — Formats the input as a number according to the locale
  • plus — Adds a number to another number
  • points — Formats the input as account points
  • round — Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places
  • times — Multiplies a number by another number

Text

  • append — Adds the specified string to the end of another string
  • capitalize — Makes the first character of a string capitalized and converts the remaining characters to lowercase
  • deserialize — Deserializes a JSON string
  • downcase — Makes each character in a string lowercase. It has no effect on strings which are already all lowercase
  • escape — Escapes a string by replacing characters with escape sequences (so that the string can be used in a URL, for example). It doesn’t change strings that don’t have anything to escape
  • escape_once — Escapes a string without changing existing escaped entities. It doesn’t change strings that don’t have anything to escape
  • hmac — Converts a string into an encrypted hash using a hash message authentication code (HMAC)
  • j — Escapes carriage returns and single and double quotes for JavaScript segments
  • lstrip — Removes all whitespace (tabs, spaces, and newlines) from the left side of a string. It does not affect spaces between words
  • markdown — Converts markdown text to HTML using GitHub-Flavored Markdown (GFM)
  • newline_to_br — Inserts an HTML line break in front of each newline in a string
  • parameterize — Converts a string to parameter format
  • prepend — Adds the specified string to the beginning of another string
  • remove — Removes every occurrence of the specified substring from a string
  • remove_first — Removes only the first occurrence of the specified substring from a string
  • replace — Replaces every occurrence of the first argument in a string with the second argument
  • replace_first — Replaces only the first occurrence of the first argument in a string with the second argument
  • rstrip — Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. It does not affect spaces between words
  • split — Splits a string into an list using the argument as a separator. split is commonly used to convert comma-separated items from a string to an list
  • strip — Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words
  • strip_html — Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words
  • strip_newlines — Removes any newline characters (line breaks) from a string
  • truncate — Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (…) is appended to the string and is included in the character count
  • truncatewords — Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (…) is appended to the string
  • unescape — Unescapes HTML escaped text
  • upcase — Makes each character in a string uppercase. It has no effect on strings which are already all uppercase
  • url_decode — Decodes a string that has been encoded as a URL or by url_encode
  • url_encode — Converts any URL-unsafe characters in a string into percent-encoded characters

Dates

  • date — Converts a timestamp into another date format. The format for this syntax is the same as strftime. The input uses the same format as Ruby’s Time.parse
  • date_add — Adds a unit of time to a date and returns a datestamp in UTC. Valid units are: years, months, weeks, days, hours, minutes, and seconds
  • datetime — Converts a date/time string to a valid timestamp
  • now — Returns a timestamp for the current date and time for the given timezone
  • time_ago — Returns a time distance string for a given date
  • time_duration — Returns a time duration string for a given number of seconds
  • today — Returns a datestamp for the current date for the given timezone

Records

  • record_fields — Returns the fields that can be accessed on the record
  • record_name — Returns the name of the record
  • record_relationships — Returns the relationships that can be accessed on the record
  • recordize — Returns a record from the liquid object. Not all liquid objects can be converted to a record

Theme

  • asset_url — Returns the url of an asset in the theme
  • t — Returns the translation for a given key for the current locale

URL

  • params — Adds query params to a url or path

Videos

  • vimeo — Returns HTML embed code for the supplied Vimeo id
  • youtube — Returns HTML embed code for the supplied YouTube id

Utilities

  • default — Sets a default value for any variable which is nil, false, or blank

Product content

Was this article helpful?

Was this article helpful?