Templating
Templates
Atuin uses MiniJinja for rendering templates, enabling flexible output customization.
Basic Syntax
- Variables:
{{ var.variable_name }} - Variables can be set by script.md blocks
- Filters:
{{ text | upper }},{{ list | join(", ") }} - Conditionals:
- Loops:
Built-in Functions
range(n): Generates a sequence →{% for i in range(3) %}{{ i }}{% endfor %}length(list): Gets list length →{{ length(users) }}default(value, fallback): Uses fallback ifNone→{{ user.name | default("Guest") }}
See Built-In Filters Reference for more.
Custom Filters
shellquote: Escapes a string for safe use in shell commands →{{ var.text | shellquote }}- Uses POSIX single-quote escaping to handle special characters like quotes, backticks, dollar signs, etc.
- Example:
echo {{ var.message | shellquote }}safely handles any characters in the message variable - Particularly useful when passing variables that might contain user input or special characters
Example Usage
Before (verbose manual escaping):
After (using shellquote filter):
The shellquote filter handles all special shell characters automatically, including:
- Single quotes (')
- Double quotes (")
- Backticks (`)
- Dollar signs ($)
- And other shell metacharacters
Built-in Filters Reference
MiniJinja provides 50+ built-in filters for data transformation and formatting. Below is a comprehensive reference:
Type Conversion
-
abs: Returns absolute value of a number -
int: Converts value to integer -
float: Converts value to floating-point number -
bool: Converts value to boolean -
string: Converts value to string -
list: Converts value to list
String Manipulation
-
upper: Converts string to uppercase -
lower: Converts string to lowercase -
capitalize: Capitalizes first character, lowercases rest -
title: Converts to title case -
trim: Removes leading and trailing whitespace -
replace: Replaces substring with another -
split: Splits string into list -
lines: Splits string into lines -
indent: Indents text with spaces -
escape: Escapes HTML special characters -
safe: Marks string as safe (no escaping) -
urlencode: URL encodes value -
format: Apply printf-style formatting
Sequence Operations
-
first: Returns first item from sequence -
last: Returns last item from sequence -
length: Returns length of sequence or string -
reverse: Reverses sequence or string -
sort: Sorts sequence -
unique: Returns unique items from sequence -
join: Joins sequence with separator -
slice: Slices sequence into sublists -
batch: Groups items into batches of given size -
chain: Chains multiple iterables together -
zip: Zips multiple iterables into tuples
Aggregation
-
sum: Sums all values in sequence -
min: Returns smallest item -
max: Returns largest item
Filtering & Selection
-
select: Filters items that pass a test -
reject: Filters items that fail a test -
selectattr: Filters by attribute value -
rejectattr: Rejects by attribute value -
map: Applies filter or gets attribute from each item -
groupby: Groups items by attribute
Dictionary Operations
-
items: Returns key-value pairs from dictionary -
dictsort: Sorts dictionary by keys -
attr: Gets attribute from object
Numeric Operations
round: Rounds number to precision
Data Serialization
-
tojson: Converts value to JSON string -
pprint: Pretty prints value for debugging
Control Flow
default: Returns default if value is undefined or falsy
Document access
The template system has full access to the entire document - blocks, text, etc.
Warning
We are still iterating on this API, and it is likely to change in future releases
First, give a block a name. Click the pencil icon next to the default name in the top left.
Then, it can be referred to via the {{ doc.named }}map, within the template system