Expand description
Askama implements a type-safe compiler for Jinja-like templates.
It lets you write templates in a Jinja-like syntax,
which are linked to a struct or an enum defining the template context.
This is done using a custom derive implementation (implemented
in askama_derive).
For feature highlights and a quick start, please review the README.
You can find the documentation about our syntax, features, configuration in our book: askama.readthedocs.io.
§Creating Askama templates
The main feature of Askama is the Template derive macro
which reads your template code, so your struct or enum can implement
the Template trait and Display, type-safe and fast:
#[derive(Template)]
#[template(
ext = "html",
source = "<p>© {{ year }} {{ enterprise|upper }}</p>"
)]
struct Footer<'a> {
year: u16,
enterprise: &'a str,
}
assert_eq!(
Footer { year: 2025, enterprise: "<em>Askama</em> developers" }.to_string(),
"<p>© 2025 <EM>ASKAMA</EM> DEVELOPERS</p>",
);
// In here you see can Askama's auto-escaping. You, the developer,
// can easily disable the auto-escaping with the `|safe` filter,
// but a malicious user cannot insert e.g. HTML scripts this way.An Askama template is a struct or enum definition which provides the template
context combined with a UTF-8 encoded text file (or inline source).
Askama can be used to generate any kind of text-based format.
The template file’s extension may be used to provide content type hints.
A template consists of text contents, which are passed through as-is, expressions, which get replaced with content while being rendered, and tags, which control the template’s logic. The template syntax is very similar to Jinja, as well as Jinja-derivatives like Twig or Tera.
Modules§
- filters
- Module for built-in filter functions
Enums§
- Error
- askama’s error type
Constants§
- NO_
VALUES - No runtime values provided.
Traits§
- DynTemplate
dyn-compatible wrapper trait aroundTemplateimplementers- Fast
Writable - Types implementing this trait can be written without needing to employ an
fmt::Formatter. - Primitive
Type - A type that is, references, or wraps a primitive type
- Template
- Main
Templatetrait; implementations are generally derived - Value
- A value in a
Valuescollection. - Values
- A runtime value store for
Template::render_with_values().
Functions§
- get_
value - Try to find
keyinvaluesand then to convert it toT.
Type Aliases§
Derive Macros§
- Template
derive - The
Templatederive macro and itstemplate()attribute.