Within Jinja templates, you can use so-called filters. Basically, those are functions applied to a first argument using pipe |
symbol.
All of our filters are implemented in templates.filters module.
There are several widely used builtin filters directly in Jinja.
We provide several filters that can be used for conversion of values:
Formats timestamp
Arguments:
iso_timestamp
-datetime
or ISO 8601str
fmt
- datetime format passed tostrftime
Example: x.created_at|datetime_format("%d/%m/%y")
Converts integer to characters
Arguments:
n
- integer >= 0, usually some index
Example: x|of_alphabet
:idea: It prints a
(for 0) to z
and then continues with aa
, ab
, etc.
Converts integer to Roman numeral
Arguments:
n
- integer >= 0, usually some index
Example: x|roman
Converts markdown to HTML
Arguments:
md_text
- string containing Markdown syntax
Example: x|roman
Ends sentence if not already ended
text
Example: "This sentence has no end"|dot
Extracts values from object by having keys
obj
- object for getting values (typicallydict
)keys
- list of keys to retrieve
Example: entities.questions|extract([uuid1, uuid2, uuid3])
These filters are handy when you need to work with repliesMap
from the plain JSON-like context.
Joins list of UUIDs into a path
uuids
- list of UUIDs
Example: [uuid1, uuid2, uuid3]|reply_path
Tries to find a reply value using a path
replies
- dict with repliespath
- list of UUIDs or path-stringxtype
(optional) - desired type of return value ("string"
,"int"
,"float"
,"list"
)
Example: replies|find_reply(path, "list")
Extracts string value from a reply if possible
reply
- object that might a reply
Example: reply|reply_str_value
Returns an empty string if not possible to extract it from the reply. Suitable for AnswerReply
, StringReply
and IntegrationReply
.
Extracts integer value from a reply if possible
reply
- object that might a reply
Example: reply|reply_int_value
Returns zero if not possible to extract it from the reply. Suitable for StringReply
with numeric value type.
Extracts float value from a reply if possible
reply
- object that might a reply
Example: reply|reply_float_value
Returns zero if not possible to extract it from the reply. Suitable for StringReply
with numeric value type.
Extracts list of strings from a reply if possible
reply
- object that might a reply
Example: reply|reply_items
Returns empty list if not possible to extract it from the reply. Suitable for MultiChoiceReply
and ItemListReply
.
These filters are more complex and add various support to template development.
Converts plain context to well-defined objects
ctx
- plain JSON-like document context
This filter is used for easier transition and might be removed in the future.