Templates
Documentation / Templates / Tera filters & functions

Tera filters & functions

Asset filters

FilterDescriptionExample
staticApp static URL prefix{{ "css/main.css" | static }}
mediaApp media URL prefix{{ "photo.jpg" | media }}

Markdown filter

FilterDescriptionExample
markdownConverts Markdown to HTML, sanitized (XSS-safe){{ page.content | markdown }}

The markdown filter declares is_safe() — its HTML is emitted unescaped, so \| safe is unnecessary and doesn't need to be added manually.

The output is sanitized via ammonia: dangerous raw HTML (<script>, on* handlers) and javascript: / data: URLs in links and images are stripped. Legitimate Markdown (headings, tables, lists, links, images, code) is preserved — user-authored Markdown can therefore be rendered safely.


Sanitize & plaintext filters

FilterDescriptionExample
sanitizeRe-sanitizes stored rich HTML and renders it as HTML{{ entry.description | sanitize }}
plaintextStrips all tags + decodes entities → plain-text preview{{ entry.description | plaintext }}

sanitize runs ammonia at render time; like markdown, it declares is_safe() directly (no \| safe to add), so the emitted HTML is always freshly cleaned — sanitization happens on output, never trusting what is stored. Use it to display a rich-text field as rendered HTML.

plaintext projects a value to plain text via the strict sanitizer (tags removed, entities decoded). It stays auto-escaped (no \| safe), so a stored &gt; is shown as >. Use it for previews — e.g. list cells — where rendered block HTML would break the layout.

The admin detail/list views use these automatically for columns classified as rich content; you rarely call them by hand.


Form filter

FilterDescriptionExample
formFull form rendering{{ my_form | form }}
form(field='xxx')Single field rendering{{ my_form | form(field='email') }}
csrf_fieldGenerates a hidden CSRF input{{ csrf_token | csrf_field }}

All three declare is_safe() — their output is emitted unescaped, \| safe is unnecessary.


Utility filters

FilterDescription
humanizeReadable identifier: "changelog_entry" → "Changelog Entry". For technical names (enum values, columns), not for user input
format_dateDate-time (NaiveDateTime) as dd/mm/yyyy HH:MM
display_timeDate-time as yyyy-mm-dd HH:MM:SS and time as HH:MM:SS, as the admin shows them; any other value unchanged
dateDate in the format of your choice ({{ d | date(format="%Y-%m-%d") }})
maskReplaces a value with as many bullets as it has characters (showing a sensitive value)
filesizeformat / filesize_formatSize in bytes, readable (1.2 MB)
slugify / slugText as a URL slug
striptagsStrips HTML tags (stays escaped)
spacelessRemoves whitespace between tags
regex_replaceRegular expression replacement
urlencode / urlencode_strictEncoding for a URL
json_encodeValue as JSON
shuffleShuffles a list

Tera functions

FunctionDescriptionExample
link(link='...')Named URL resolution{{ link(link='index') }}
csrf_token()The request's masked CSRF token{{ csrf_token() }}
now()Current date-time{{ now() }}
get_random(start, end)Random integer{{ get_random(start=1, end=10) }}

Auto-injected context variables

VariableDescription
csrf_tokenMasked CSRF token (used by {% csrf %} and | csrf_field)
csp_nonceCSP nonce value for the header (used by {% csp %})
messagesRequest flash messages
current_userThe signed-in account (username, id, rank…), read from the database on every request; absent for an anonymous visitor
debugThe value of DEBUG
devtrue with RUNIQUE_ENV=dev
current_pathCurrent URL path, without query string (useful for rel="canonical", og:url, active navigation)