Jinja2 Documentation and Custom Filters Guide
Introduction to Jinja2
Jinja2 is a modern and designer-friendly templating language for Python, modeled after Django’s templates. It is fast, widely used, and secure with the optional sandboxed template execution environment.
Official Documentation
For comprehensive details, you can refer to the official Jinja2 documentation:
Timezones
Filters that render a timestamp (datetime, date) interpret it as UTC by
default. This is unchanged behaviour and applies to every existing template.
To render in a local timezone, pass the optional tz argument with an
IANA timezone name
such as Europe/Paris or Asia/Seoul. Daylight saving time is handled
automatically, per timestamp — a slot in July renders at UTC+02:00 and a slot in
December at UTC+01:00 without any work in the template.
Pass tz wherever you format, not only where you format the hour. Converting to
a local timezone can move the date as well as the time, so the day name (%w,%A), day number (%d) and full date (%Y-%m-%d) all change:
{{ 1787092200 | datetime('%Y-%m-%d %H:%M') }}
{{ 1787092200 | datetime('%Y-%m-%d %H:%M', tz='Europe/Paris') }}Output:
2026-08-18 22:30
2026-08-19 00:30
If tz is omitted the timestamp is rendered in UTC. If tz is not a recognised
timezone name, the filter falls back to UTC rather than failing the template.
Custom Filters
For more advanced data management and date manipulation, Alcmeon already implemented the following custom filters.
parse_iso_date
- Can be applied on an ISO date and return a Python datetime object.
- Supports any format that is allowed by Python datetime.fromisoformat() function. See Documentation
date = '2011-11-04T00:05:23Z' | parse_iso_date
date_now
- No input required. Return the date of the execution as a Python datetime object.
now = '' | date_now
add_days
- Must be applied on a Python datetime and need a number of days to add. Works with negative number of days if you want to substract days.
updated_date = date | add_days(4) # Add 4 days to the variable 'date'
add_hours
- Must be applied on a Python datetime and need a number of hours to add. Works with negative number of hours if you want to substract hours.
updated_date = date | add_hours(4) # Add 4 hours to the variable 'date'
add_minutes
- Must be applied on a Python datetime and need a number of minutes to add. Works with negative number of minutes if you want to substract minutes.
updated_date = date | add_minutes(4) # Add 4 minutes to the variable 'date'
datetime
- Formats a timestamp to a readable date and time string.
- Takes an optional format input. Default format is
%Y-%m-%d @ %H:%M. - Takes an optional
tzargument (IANA timezone name). Defaults to UTC.
"1745392360" | datetime
"1745392360" | datetime("%Y-%m-%d %H:%M:%S")
"1745392360" | datetime("%Y-%m-%d %H:%M", tz="Europe/Paris")
"1735732800" | datetime("%Y-%m-%d %H:%M", tz="Europe/Paris")
"1745392360" | datetime("%Y-%m-%d %H:%M %z", tz="Europe/Paris")
Output:2025-04-23 @ 07:12
2025-04-23 07:12:40
2025-04-23 09:12
2025-01-01 13:00
2025-04-23 09:12 +0200
date
- Formats a timestamp to a readable date string.
- Takes an optional format input. Default format is
%Y-%m-%d. - Takes an optional
tzargument (IANA timezone name). Defaults to UTC.
"1745392360" | date
"1745392360" | date("%Y %m %d")
"1787092200" | date(tz="Europe/Paris")
Output:2025-04-23
2025 04 23
2026-08-19
ddatetime
- Formats a Python datetime object to a readable date and time string.
- Takes an optional format input. Default format is %Y-%m-%d @ %H:%M.
datetime_obj | ddatetime
datetime_obj | ddatetime("%Y-%m-%d %H:%M:%s")
Output:2025-04-23 @ 07:122025-04-23 07:12:40
ddate
- Formats a Python datetime object to a readable date string.
- Takes an optional format input. Default format is %Y-%m-%d.
datetime_obj | ddate
datetime_obj" | ddate("%Y %m %d")
Output:2025-04-232025 04 23
to_datetime
- Converts a timestamp into a Python datetime object (in UTC), so that
timestamps can be used with the datetime-object filters (in_tz,add_days,add_hours,add_minutes,ddatetime,ddate).
slot = "1745392360" | to_datetimein_tz
- Must be applied on a Python datetime. Converts it to the given timezone,
keeping the same instant in time. - Requires an IANA timezone name. Falls back to UTC if the name is not
recognised. - Use this instead of the
tzargument when you format the same value several
times: convert once, then format as often as you need.
{% set slot = "1787092200" | to_datetime | in_tz("Europe/Paris") %} {{ slot | ddate }} at {{ slot | ddatetime("%Hh%M") }}Output: 2026-08-19 at 00h30
datetime_diff
- Calculates the difference between the current datetime and a given timestamp, returning a tuple with the unit and value.
"1745392360" | datetime_diff
Output one of:('s', 30) -> 30 seconds of difference('m', 12) -> 12 minutes of difference('h', 3) -> 3 hours of difference('d', 14) -> 14 days of difference
If the difference is less than 1 minute, it is displayed in seconds. If the difference is between 1 minute and 1 hour, it is displayed in minutes. For differences between 1 hour and 1 day, it is displayed in hours. For differences greater than 1 day, it is displayed in days.
datetime_diff
- Calculates the difference in days between the current date and a given timestamp.
"1745392360" | datetime_diff
Output one of:1 <= 1 day difference14 14 days of difference
addslashes
- Escapes special characters in a string.
"Hello\nWorld" | addslashes
Output: Hello\\nWorld
domain_from_url
- Extracts the domain from a URL.
"https://www.example.com/path" | domain_from_url
Output: www.example.com
render_links
- Converts URLs in a string to clickable HTML links.
"Visit https://www.example.com for more info." | render_links
Output: Visit <a href="https://www.example.com" target="_blank">https://www.example.com</a> for more info.
json_escape
- Escapes special characters for use in JSON strings.
"{"key": "v/al'ue"}" | json_escape
Output: {\"key\": \"v\/al\'ue\"}
escape_url
- URL-encodes a string.
"Hello World" | escape_url
Output: Hello+World
str
- Converts a number to a string.
{{ 10 | str }}
Output: "10"
to_int
- Converts a string to a number.
{{ "10" | str }}
Output: 10
lower
- Converts a string to lowercase.
{{ "ABC" | lower }}
Output: abc
set_exit
- Allows to set an exit node in the Code box. Can only be used in this context. Check this documentation for more details
{{ set_exit("exit_ref" }}
Output: Nothing, only set an exit.
log
- Allows to log data in the Code box. Can only be used in this context. Check this documentation for more details
{{ log("Test" }}
Output: Nothing, only store log in debug context.
Updated 16 days ago