LogoLogo
HomePricingSign inRegister
  • PDFMonkey Documentation
  • Guides
    • From zero to generating your first Document
    • Generating your first Document with Zapier
    • Generating your first Document with Make
    • Making your first API call
  • PDFMonkey Features
    • 14-day Pro trial
    • Automatic deletion (TTL)
    • CLI
    • Generating images
    • Share links
    • Synchronous generation
    • Snippets
    • Webhooks
  • Frequent questions
    • Troubleshooting
      • My Document is blank
      • My data is not showing up in the Document
      • The Download URL is empty
    • What can you do with PDFMonkey?
    • What happens if I use all of my quota?
    • How do I change my password?
    • How do I delete my account?
    • Authoring Templates
      • Can I import an existing PDF or Word file in PDFMonkey?
      • What are the Template test data?
      • Can you create templates for me?
      • Can I display the number of the current page in the content?
      • Can I use links?
    • Privacy and security
      • What data do you keep and for how long?
      • How is my data secured?
      • Do you have a DPA
    • Compliance
  • How-tos
    • Adding a header or footer to your document
    • Including images in your documents
    • Styling your documents
      • Writing your own CSS
      • Using external libraries
      • Providing per-Document styles
      • Dealing with page breaks
    • Using different fonts
      • Handling special characters (UTF-8, Hebrew, Chinese, etc)
      • Using different fonts in header and footer
    • Using JavaScript
      • What are the available JavaScript features
      • JavaScript and Dynamic Data
      • Using external libraries
      • Displaying dates and time using JS
      • Including charts in your Documents
      • Debugging your JavaScript
    • Setting the filename of the generated Document
    • Changing the size of the page and its margins
    • Forcing a single page or use a full-page background
    • Using QR Codes
  • Integrations
    • List of integrations
    • Zapier
      • Generating your first Document with Zapier
      • Document generation options in Zapier
      • Reacting to generated documents in Zapier
      • TODO Retrieving a Document in Zapier
      • TODO Deleting a document using Zapier
      • Fixing frequent Zapier errors
    • Make (formerly Integromat)
      • Generating your first Document with Make
    • Workato
      • Generating a document with Workato
      • Deleting a document using Workato
      • Reacting to generated documents in Workato
    • Glide
    • Bubble
    • InvoiceBerry (via Zapier)
    • Ruby SDK
  • References
    • The Document Lifecycle
    • Liquid Reference
      • Introduction
      • Defining and using dynamic data
      • Variables
      • Naming variables
      • Conditions (if/else)
      • Iteration (dealing with lists)
      • Filters (data transformation)
        • Built-in filters
        • PDFMonkey filters
      • PDFMonkey Liquid tags
      • Whitespace control
    • API Reference
      • Documents
      • Templates
Powered by GitBook
On this page
  • Array filters
  • push
  • slice_by
  • sum
  • to_sentence
  • where_exp
  • Date and time filters
  • in_time_zone
  • URL filters
  • ensure_protocol
  • Number filters
  • format
  • with_delimiter
  • HTML filters
  • entities
  • JSON filters
  • json
  • parse_json

Was this helpful?

  1. References
  2. Liquid Reference
  3. Filters (data transformation)

PDFMonkey filters

Array filters

push

Adds an item to an array

Input
{% assign arr = "earth wind" | split: " " %}
{% assign arr = arr | push: "fire" %}

{{arr | to_sentence}}
Output
earth, wind and fire

slice_by

Slices an array in groups of N elements.

Input
{% assign reindeers = "Dasher Dancer Prancer Vixen Comet Cupid Donner Blitzen Rudolph" | split: " " %}
{% assign reindeerPairs = reindeers | slice_by: 2 %}

{% for reindeerPair in reindeerPairs %}
  Pair:
  {% for reindeer in reindeerPair %}
    - {{reindeer}}
  {% endfor %}  
{% endfor %}
Output
  Pair:
    - Dasher
    - Dancer
  Pair:
    - Prancer
    - Vixen
  Pair:
    - Comet
    - Cupid
  Pair:
    - Donner
    - Blitzen
  Pair:
    - Rudolph

sum

Returns the sum of a numbers array.

Let's say you have this in your data:

JSON
{
  "array": [1, 2, 3, 4, 5]
}
Input
{{array | sum}}
Output
15

to_sentence

Converts the array to a comma-separated sentence where the last element is joined by the connector word.

Input
{% assign arr = "earth wind" | split: " " %}
{% assign arr = arr | push: "fire" %}

{{arr | to_sentence}}
{{arr | to_sentence: ' - '}}
{{arr | to_sentence: ' - ', 'and finally '}}cod
earth, wind and fire
earth - wind and fire
earth - wind and finally fire

where_exp

Let's start with the data:

JSON
{
  "products": [
    { "name": "Product 1", "price": 1.00 },
    { "name": "Product 2", "price": 2.00 },
    { "name": "Product 3", "price": 3.00 },
    { "name": "Product 4", "price": 2.00 },
    { "name": "Product 5", "price": 1.00 }
  ]
}
Input
{% assign cheapProducts = products | where_exp: "prod", "prod.price < 1" %}

{% for product in cheapProducts %}
- {{product.name}}
{% endfor %}
- Product 1
- Product 5

Date and time filters

in_time_zone

Input
{{"2050-01-02 12:34:56" | in_time_zone: "Pacific/Galapagos" | date: "%Y-%m-%d %H:%M"}}
2050-01-02 06:34

URL filters

ensure_protocol

You might get asset URLs that don’t include any protocol. Sadly our rendering engine doesn’t support this type of URL. For this reason we provide ensure_protocol that will add a protocol as needed:

Input
{{"//example.com/some-picture.jpg" | ensure_protocol}}
{{"//example.com/some-picture.jpg" | ensure_protocol: "http"}}
{{"http://example.com/some-picture.jpg" | ensure_protocol}}
Output
https://example.com/some-picture.jpg
http://example.com/some-picture.jpg
http://example.com/some-picture.jpg

Number filters

format

Input
{{5 | format: "%05d"}}      -> 00005
{{5 | format: "%08.3f"}}    -> 0005.000
{{5 | format: "%.2f"}}      -> 5.00
{{5.1234 | format: "%.2f"}} -> 5.12
Output
00005
0005.000
5.00
5.12

with_delimiter

For basic number formatting like money for instance, the with_delimiter filter will help you set a thousand delimiter, a decimal separator and the precision.

Input
{{12345678 | with_delimiter}}
{{'123456' | with_delimiter}}
{{12345678.05 | with_delimiter}}
{{12345678 | with_delimiter, delimiter: '.'}}
{{12345678 | with_delimiter, delimiter: ','}}
{{12345678 | with_delimiter, delimiter: ',', precision: 2}}
{{12345678.05 | with_delimiter, separator: ' '}}
{{12345678.05 | with_delimiter, delimiter: ' ', separator: ','}}
{{'123a' | with_delimiter}}
Output
12,345,678
123,456
12,345,678.05
12.345.678
12,345,678
12,345,678.00
12,345,678 05
12 345 678,05
123a

HTML filters

entities

Input
{{"Marie Skłodowska Curie" | entities}}
Output
Marie Sk&lstrok;odowska Curie

JSON filters

json

Input
{{'banana, apple' | split: ', ' | json}}
Output
["banana", "apple"]

parse_json

If you have a value in your payload that contains a JSON string, you can use the parse_json filter to parse it and use it as additional data.

Input
{% assign obj = '{ "key": "value" }' | parse_json %}
{{obj.key}}
Output
value

PreviousBuilt-in filtersNextPDFMonkey Liquid tags

Last updated 1 month ago

Was this helpful?

Similar to Liquid's but accepts an expression.

The format filter is useful for advanced number formatting. For simpler formatting, prefer .

This filter can be very useful if you have to deal with accented or special characters inside the . It will convert any non-latin character to its .

If you need to insert in its original JSON format (like we do for instance) the json filter is what you need. Notice it’s returning a string, not the object itself.

header or footer
HTML entity
dynamic data
for charts
with_delimiter
where