Skip to main content

format

Function format 

Source
pub fn format(
    state: &mut State<'_, '_>,
    format_str: &Value,
    format_args: Rest<ValueOrKwargs>,
) -> Result<Value, Error>
Expand description

Apply the given values to a printf-style format string.

{{ "%s, %s!"|format(greeting, name) }}
-> Hello, World!

In many cases, the str.format() style could be more convenient than the printf-style formatting:

{{ "{}, {name}!".format(greeting, name="Alice") }}
-> Hello, Alice!

This option is available through minijinja-contrib’s pycompat feature.