5 unstable releases
new 0.3.2 | Apr 12, 2025 |
---|---|
0.3.1 | Apr 12, 2025 |
0.2.1 | Apr 10, 2025 |
0.1.1 | Apr 4, 2025 |
0.1.0 | Apr 2, 2025 |
#569 in Template engine
383 downloads per month
70KB
754 lines
anvil-liquid
An Anvil integration for Liquid templates.
Installation
[dependencies]
anvil-liquid = "0.3.1"
anvil = "0.3.0"
liquid = "0.26.11"
serde = { version = "1.0", features = ["derive"] }
Usage
use anvil::Forge;
use anvil_liquid::prelude::*; // Import extension traits and functions
use serde::Serialize;
use liquid::ParserBuilder;
use std::sync::LazyLock;
// Define a parser for your templates
static PARSER: LazyLock<liquid::Parser> =
LazyLock::new(|| ParserBuilder::with_stdlib().build().unwrap());
// Define a serializable template context
#[derive(Serialize)]
struct MyTemplate {
name: String,
}
// Use macro to implement the Water trait with a template file
make_liquid_template!(MyTemplate, "path/to/template.txt", PARSER);
fn main() -> Result<(), Box<dyn std::error::Error>> {
let template = MyTemplate { name: "World".to_string() };
// Generate a new file
generate(&template).forge("hello.txt")?;
// Append to an existing file
append(&template).forge("log.txt")?;
Ok(())
}
Dependencies
~6–8MB
~150K SLoC