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:
| Parameter | Description |
|---|---|
style | CSS 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:
| Parameter | Description | Default |
|---|---|---|
type | Barcode format (required) — see supported types below | — |
style | CSS styles | — |
quiet_zone | Distance from border to barcode (mm) | 0 |
font_size | Text font size (pt). Set to 0 to hide text | 10 |
text_distance | Distance between barcode and text (mm) | 5.0 |
module_width | Width of one barcode module (mm) | 0.2 |
module_height | Height of barcode modules (mm) | 15.0 |
Supported barcode types:
| Type | Description |
|---|---|
ean8 | EAN8 |
ean13 / ean | EAN13 |
gtin / ean14 | EAN14 |
jan | JAN |
upc / upca | UPCA |
isbn / isbn13 / gs1 | ISBN13 |
isbn10 | ISBN10 |
issn | ISSN |
code39 | Code39 |
pzn | PZN |
code128 | Code128 |
itf | ITF |
gs1_128 | GS1-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:
| Parameter | Description |
|---|---|
table_class | CSS 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:
| Parameter | Description | Default |
|---|---|---|
epoch_time | Unix timestamp (seconds since January 1, 1970 UTC) | — |
timezone_hour | Timezone 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:
| Function | Description | Example |
|---|---|---|
gt | Greater than | gt(val1, val2) |
gte | Greater than or equal to | gte(val1, val2) |
lt | Less than | lt(val1, val2) |
lte | Less than or equal to | lte(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
- Default Filters — standard Jinja2 filters
- Examples — practical template patterns