Skip to content
Start free

Liquid Filters

Open in ClaudeOpen in ChatGPT

HTML/CSS Templates use the Liquid markup language. You can use “filters” to format and modify any values before inserting them into the page.

DocSpring supports most of the filters that you can find in the Liquid documentation. However, you may find some filters in Shopify’s Liquid documentation that we don’t support. Please contact us if you would like us to add a new Liquid filter.

  • Use the newline_to_br filter to replace newline characters (\n) with HTML line breaks (<br/>). Otherwise, any multi-line strings will be displayed on a single line.
  • In a template that escapes HTML in data, newline_to_br escapes the text and keeps its line breaks.

Here are some Liquid filters that are unique to DocSpring:

Prints a value as HTML, in a template that escapes HTML in data. Use it only for HTML you trust, and put it last: a filter after it escapes what it adds.

{{ terms_html | raw }}

In a template that doesn’t escape data, every value is printed as HTML already, and raw changes nothing.


{{ count | pluralize: "<singular>" }}
{{ count | pluralize: "<singular>", "<plural>" }}

Pluralize a string based on the count.

Parameters:

  • singular (required) - String to use when count is 1
  • plural - String to use when count is 0 or more than 1 (defaults to adding an “s” to singular)

Examples:

{{ 1 | pluralize: "thing" }}
=> "thing"
{{ 2 | pluralize: "thing" }}
=> "things"
{{ 0 | pluralize: "city", "cities" }}
=> "cities"

{{ number | delimited }}
{{ number | delimited: "<delimiter>", "<separator>" }}

Formats a number with grouped thousands (e.g. 12,324.)

Parameters:

  • delimiter - Sets the thousands delimiter (defaults to “,”).
  • separator - Sets the separator between the fractional and integer digits (defaults to “.”).

Examples:

{{ 1000 | delimited }}
=> "1,000"
{{ 1000000 | delimited }}
=> "1,000,000"
{{ 1000 | delimited: " " }}
=> "1 000"
{{ 1000.45 | delimited: ".", "," }}
=> "1.000,45"

{{ number | currency }}
{{ number | currency: "<unit>", "<delimiter>", "<separator>", "<format>", "<negative_format>", <precision> }}

Formats a number as a currency, with grouped thousands and two decimal places (e.g. $12,324.00.)

Parameters:

  • unit - Sets the denomination of the currency (defaults to “$”).
  • delimiter - Sets the thousands delimiter (defaults to “,”).
  • separator - Sets the separator between the fractional and integer digits (defaults to “.”).
  • format - Sets the format for non-negative numbers (defaults to “%u%n”). Fields are %u for the currency, and %n for the number.
  • negative_format - Sets the format for negative numbers (defaults to prepending a hyphen to the formatted number given by format). Accepts the same fields as format, except %n is here the absolute value of the number. Pass nil to keep the default.
  • precision - Sets the level of precision for decimal places (defaults to 2). Must be a number, not a quoted string.

Examples:

{{ 1 | currency }}
=> "$1.00"
{{ 1000 | currency }}
=> "$1,000.00"
{{ 1234.56 | currency: "€", ".", "," }}
=> "€1.234,56"
{{ -1234567890.50 | currency: "$", ",", ".", "%u%n", "(%u%n)" }}
=> ($1,234,567,890.50)
{{ 1234567890.50 | currency: "R$", "", ",", "%n %u" }}
=> 1234567890,50 R$
{{ 1.5 | currency: "$", ",", ".", "%u%n", nil, 3 }}
=> $1.500

{{ date | in_time_zone: "<timezone>" }}
{{ 'now' | in_time_zone: "<timezone>" }}

Convert a date into a specific timezone. You can also pass 'now' or 'today' to use the current time.

Include a UTC offset in timestamps you pass to in_time_zone (e.g. 2024-05-01T09:00:00Z). A timestamp without one is read in your account’s time zone, which you can set in your account settings. Date-only values are read as midnight and can shift to the previous day, so format them with date directly. An unrecognised timezone is ignored, and the time is shown in your account’s time zone instead. Templates created before 29 October 2026 use the server’s time zone (US Eastern) instead of the account’s, so their PDFs don’t change.

Parameters:

Examples:

{{ 'now' | in_time_zone: "America/New_York" | date: "%Y-%m-%d %H:%M" }}
=> "2020-04-30 04:04"
{{ 'now' | in_time_zone: "Asia/Kuala_Lumpur" | date: "%Y-%m-%d %H:%M" }}
=> "2020-04-30 16:04"