MCPcopy Index your code
hub / github.com/askama-rs/askama

github.com/askama-rs/askama @v0.16.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.16.0 ↗ · + Follow
2,814 symbols 5,253 edges 238 files 132 documented · 5%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

askama

Crates.io GitHub Workflow Status Book docs.rs

Askama implements a template rendering engine based on Jinja, and generates type-safe Rust code from your templates at compile time based on a user-defined struct to hold the template's context.

At some point, Askama got forked into Rinja (explained here) before getting merged back into Askama.

All feedback welcome! Feel free to file bugs, requests for documentation and any other feedback to the issue tracker.

You can find the documentation about our syntax, features, configuration in our book: askama.rs.

Have a look at our Askama Playground, if you want to try out askama's code generation online.

Feature highlights

  • Construct templates using a familiar, easy-to-use syntax
  • Benefit from the safety provided by Rust's type system
  • Template code is compiled into your crate for optimal performance
  • Debugging features to assist you in template development
  • Templates must be valid UTF-8 and produce UTF-8 when rendered
  • Works on stable Rust

Supported in templates

  • Template inheritance
  • Loops, if/else statements and include support
  • Macro support
  • Variables (no mutability allowed)
  • Some built-in filters, and the ability to use your own
  • Whitespace suppressing with '-' markers
  • Opt-out HTML escaping
  • Syntax customization

How to get started

First, add the askama dependency to your crate's Cargo.toml:

cargo add askama

Now create a directory called templates in your crate root. In it, create a file called hello.html, containing the following:

Hello, {{ name }}!

In any Rust file inside your crate, add the following:

use askama::Template; // bring trait in scope

#[derive(Template)] // this will generate the code...
#[template(path = "hello.html")] // using the template in this path, relative
                                 // to the `templates` dir in the crate root
struct HelloTemplate<'a> { // the name of the struct can be anything
    name: &'a str, // the field name should match the variable name
                   // in your template
}

fn main() {
    let hello = HelloTemplate { name: "world" }; // instantiate your struct
    println!("{}", hello.render().unwrap()); // then render it.
}

You should now be able to compile and run this code.

Extension points exported contracts — how you extend this code

Values (Interface)
A runtime value store for [`Template::render_with_values()`][crate::Template::render_with_values]. [10 implementers]
askama/src/values.rs
Escaper (Interface)
An escaper for some context, e.g. [`Html`]. [3 implementers]
askama_escape/src/lib.rs
ToDevNull (Interface)
(no doc) [1 implementers]
fuzzing/fuzz/src/filters.rs
FastWritable (Interface)
Types implementing this trait can be written without needing to employ an [`fmt::Formatter`]. [30 implementers]
askama/src/lib.rs
RunScenario (Interface)
(no doc) [1 implementers]
fuzzing/fuzz/src/lib.rs
AsIndent (Interface)
[`|indent`](indent). ``` # use askama::filters::AsIndent; assert_eq!(4.as_indent(), " "); assert_eq!(" -> ".as_inden [8 …
askama/src/filters/indent.rs
Scenario (Interface)
(no doc)
fuzzing/fuzz/src/lib.rs
HtmlSafe (Interface)
Types that implement this marker trait don't need to be HTML escaped Please note that this trait is only meant as speed [6 …
askama/src/filters/escape.rs

Core symbols most depended-on inside this repo

new
called by 547
askama_derive/src/input.rs
span
called by 204
askama_derive/src/input.rs
ws
called by 136
askama_parser/src/lib.rs
span_for_node
called by 123
askama_derive/src/heritage.rs
push
called by 76
askama_derive/src/generator.rs
as_ref
called by 64
askama_parser/src/lib.rs
into_token_stream
called by 63
askama_derive/src/integration.rs
clone
called by 59
askama_derive/src/spans.rs

Shape

Class 1,119
Function 1,014
Method 575
Enum 84
Interface 22

Languages

Rust99%
Python1%

Modules by API surface

testing/tests/loop_else.rs130 symbols
askama_parser/src/lib.rs100 symbols
testing/tests/simple.rs92 symbols
testing/tests/filters.rs76 symbols
askama_parser/src/expr.rs74 symbols
testing/tests/macro.rs70 symbols
askama_parser/src/tests.rs55 symbols
askama_parser/src/node.rs54 symbols
testing/tests/loops.rs53 symbols
askama_derive/src/generator.rs52 symbols
testing/tests/calls.rs51 symbols
askama_derive/src/generator/filter.rs50 symbols

For agents

$ claude mcp add askama \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact