Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Liquid Hello World

  • Depened on the liquid crate
[package]
name = "liquid-hello-world"
version = "0.1.0"
edition = "2024"


[dependencies]
liquid = "0.26"
  • Start with a template that is part of the Rust source code.
  • We use the parse and build methods to create the template object.
  • We use unwrap here which is probably not ideal, but it simlifies the examples.
  • Using the liquid::object! macro we create an object from the data we would like to pass to the template.
  • Using the render method we combine the data with the template and generate (render) the resuling text.
fn main() {
    let template = liquid::ParserBuilder::with_stdlib()
        .build()
        .unwrap()
        .parse("Welcome to {{name}}")
        .unwrap();

    let globals = liquid::object!({
        "name": "Liquid"
    });
    let output = template.render(&globals).unwrap();

    println!("{}", output);
}
Welcome to Liquid

  • parse
  • build
  • object!
  • render