- parse
- include_str
Liquid Hello World embed template file
- If you would like to supply the temlates, probably the easiest is to embed them in the binary.
- Using include_str! we can embed a text-file in the compiled binary of our Rust code.
- In the source repository we have the templates as external files, but during build they are embedded in the code.
examples/liquid/liquid-hello-world-embedded-file/src/main.rs
fn main() { let template = include_str!("../template.txt"); let template = liquid::ParserBuilder::with_stdlib() .build() .unwrap() .parse(template) .unwrap(); let name = String::from("Liquid"); let globals = liquid::object!({ "name": name }); let output = template.render(&globals).unwrap(); println!("{}", output); }
examples/liquid/liquid-hello-world-embedded-file/template.txt
Hello {{name}}!