Liquid Hello World embed template file
-
parse
-
include_str!
-
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.
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); }
Hello {{name}}!