Skip to content

Jinja Filters Reference

Orchid registers 70+ custom Jinja2 filters in orchid/jinja_filters.py. Before writing Python logic inside a template, check here — the filter you need likely already exists.

How to use filters

{# Basic usage #}
{{ value | filter_name }}
{# With arguments #}
{{ value | filter_name(arg1, arg2) }}
{# Chained #}
{{ value | filter_one | filter_two }}

Formatting filters

Display and text

FilterWhat it does
capitalize_wordsCapitalizes every word: 'hello world''Hello World'
capitalize_firstCapitalizes first character only
bool_readabilityConverts boolean to 'Yes' / 'No' / '--'
bool_readability(true_text, false_text)Custom true/false labels
clean_question_codeRemoves pipes from question codes
clean_sort(attr)Sorts a list of objects by attribute with error handling

Usage examples:

{{ name | capitalize_words }}
{{ field | bool_readability }}
{{ field | bool_readability('Active', 'Inactive') }}
{{ items | clean_sort('name') }}

Contact and address

FilterOutput
addressMulti-line formatted address (street, city, state, zip, country)
phone_readabilityFormats as (555) 123-4567
email_logo_urlPublic proxy URL for agency logos safe for emails
{{ contact | address }}
{{ user.phone | phone_readability }}
{{ agency | email_logo_url }}

Dates and times

FilterOutput
date_readabilityJanuary 15, 2025
time_readability2:30 PM
from_utc(timezone)Converts UTC datetime to local timezone
{{ case.created_at | date_readability }}
{{ event.time | time_readability }}
{{ ts | from_utc(timezone) }}

Money

FilterOutput
currency$1,234.56
{{ amount | currency }}

Case and type mapping

FilterWhat it does
case_type_filter'surrogate''GC Case', 'donor''ED Case', etc.
case_type_short'surrogate''GC', 'donor''ED', etc.
contract_role'donor''Egg Donor', 'surrogate''Surrogate', etc.
{{ case.case_type | case_type_filter }}
{{ case.case_type | case_type_short }}
{{ role | contract_role }}

File and media filters

FilterWhat it does
cloudfrontGenerates a presigned CloudFront URL from an S3 key
file_iconReturns a CSS class / icon name based on file extension
base64Base64-encodes a string value
{{ doc.s3_key | cloudfront }}
{{ doc.filename | file_icon }}
{{ value | base64 }}

Security filters

FilterWhat it does
sanitize_noteStrips dangerous HTML, allows safe tags (bold, italic, links)
{{ note.body | sanitize_note }}

Use sanitize_note whenever rendering user-provided text that may contain HTML. Never use | safe on raw user content.

Adding a new filter

Filters are registered in orchid/jinja_filters.py using the @filters.app_template_filter() decorator:

@filters.app_template_filter('my_filter')
def my_filter(value, arg1=None):
"""Brief docstring explaining what this filter does."""
if value is None:
return ''
return str(value)

Rules for new filters:

  • Always handle None input gracefully — templates frequently pass None
  • Return a string (be explicit)
  • Add the filter to this reference page after adding it to the code
  • Keep filters pure — no database queries, no side effects