ascii_str.rs |
|
3738 |
error.rs |
|
8520 |
filters |
|
|
helpers.rs |
|
6344 |
html.rs |
|
4283 |
lib.rs |
[](https://crates.io/crates/askama)
[](https://github.com/askama-rs/askama/actions/workflows/rust.yml)
[](https://askama.readthedocs.io/)
[](https://docs.rs/askama/)
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`](https://crates.io/crates/askama_derive)).
For feature highlights and a quick start, please review the
[README](https://github.com/askama-rs/askama/blob/master/README.md).
You can find the documentation about our syntax, features, configuration in our book:
[askama.readthedocs.io](https://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`][std::fmt::Display], type-safe and fast:
```rust
# use askama::Template;
#[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](http://jinja.pocoo.org/),
as well as Jinja-derivatives like [Twig](https://twig.symfony.com/) or
[Tera](https://github.com/Keats/tera). |
14753 |
values.rs |
|
8127 |