Skip to main content

APITemplate.io Filters

These filters and functions are custom to APITemplate.io and extend what standard Jinja2 offers. They let you generate QR codes, barcodes, HTML tables, format dates, and more directly inside your templates.

render_qrcode

Converts a value into a QR code image.

Syntax:

{{ value | render_qrcode(style="css styles") }}

Example:

{
"website": "https://apitemplate.io",
"email": "hello@apitemplate.io"
}
{{ website | render_qrcode(style='width: 100px; height: 100px; background: white;') }}
QR code for {{ website }}

Parameters:

ParameterDescription
styleCSS styles applied to the QR code image

render_barcode

Converts a value into a barcode image.

Syntax:

{{ value | render_barcode(type="barcode_type", style="css styles") }}

Example:

{
"document_id": "889856789012"
}
{{ document_id | render_barcode(type='ean13', style='height: 100px;', quiet_zone=0, font_size=10, text_distance=5, module_width=0.2, module_height=15.0) }}
Barcode for {{ document_id }}

Parameters:

ParameterDescriptionDefault
typeBarcode format (required) — see supported types below
styleCSS styles
quiet_zoneDistance from border to barcode (mm)0
font_sizeText font size (pt). Set to 0 to hide text10
text_distanceDistance between barcode and text (mm)5.0
module_widthWidth of one barcode module (mm)0.2
module_heightHeight of barcode modules (mm)15.0

Supported barcode types:

TypeDescription
ean8EAN8
ean13 / eanEAN13
gtin / ean14EAN14
janJAN
upc / upcaUPCA
isbn / isbn13 / gs1ISBN13
isbn10ISBN10
issnISSN
code39Code39
pznPZN
code128Code128
itfITF
gs1_128GS1-128

render_table

Converts a JSON array into an HTML table.

Syntax:

{{ json_array | render_table(table_class="css class") }}

Example:

{
"title": "Product list",
"items": [
{"item_name": "Product 1", "price": "USD 200.00"},
{"item_name": "Product 2", "price": "USD 300.00"}
]
}
{{ items | render_table(table_class='table') }}

Parameters:

ParameterDescription
table_classCSS class applied to the <table> element

json

Renders a JSON object as JSON in the HTML output. Useful for debugging or displaying raw data.

Syntax:

{{ json_object | json }}

Example:

<pre>{{ my_data | json }}</pre>

strptime

Parses a date string into a datetime object. Typically used together with strftime to reformat dates.

Syntax:

{{ strptime(date_string, format) }}

Example:

{
"due_date": "2022-08-16T15:57:31.325116Z"
}
{{ strptime(due_date, "%Y-%m-%dT%H:%M:%S.%fZ") }}

strftime

Formats a datetime object into a string.

Syntax:

{{ strftime(datetime_object, format) }}

The most common pattern is parsing and reformatting in one step:

{{ strftime(strptime(due_date, "%Y-%m-%dT%H:%M:%S.%fZ"), "%d/%m/%y") }}

Output: 16/08/22

See Python's strftime reference for the full list of format codes.

epoch_to_datetime

Converts a Unix epoch timestamp into a datetime object.

Syntax:

{{ epoch_to_datetime(epoch_time, timezone_hour) }}

Parameters:

ParameterDescriptionDefault
epoch_timeUnix timestamp (seconds since January 1, 1970 UTC)
timezone_hourTimezone offset in hours (e.g. 8 for UTC+8, -5 for UTC-5)0

Example:

{
"created_at": 1665494864
}
{{ strftime(epoch_to_datetime(created_at, 8), "%y-%m-%d") }}

Output: 22-10-11

Format currency / numbers

Use Python's string formatting to display numbers as currency or formatted values.

Syntax:

{{ "${:,.2f}".format(value) }}

Example:

{
"gross_total": 2000.50
}
{{ "${:,.2f}".format(gross_total) }}

Output: $2,000.50

More formatting patterns:

{{ "{:,.2f}".format(amount) }}        <!-- 1,234.56 -->
{{ "${:,.0f}".format(amount) }} <!-- $1,235 -->
{{ "{:.2f}%".format(percentage) }} <!-- 15.50% -->

Comparison functions

APITemplate.io also provides comparison functions as an alternative to standard operators:

FunctionDescriptionExample
gtGreater thangt(val1, val2)
gteGreater than or equal togte(val1, val2)
ltLess thanlt(val1, val2)
lteLess than or equal tolte(val1, val2)

Example:

{% if gt(life_span, 160) and lt(life_span, 180) %}
{{ product }} is expiring soon!
{% elif gte(life_span, 180) %}
{{ product }} has expired!
{% endif %}

Next steps