- parse_file
Liquid Hello World read template from file
- Templates are usually much biggger than what we had in the first example.
- We usually prefer to keep the templates as an external files.
- Instead of parse we can use parse_file to load the template from an external file.
- This happens at run-time so you will need to supply the templates outside of the binary or the user will need to create the templates.
Hello Liquid!
examples/liquid/liquid-hello-world-from-file/src/main.rs
fn main() { let filename = "template.txt"; let template = liquid::ParserBuilder::with_stdlib() .build() .unwrap() .parse_file(filename) .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-from-file/template.txt
Hello {{name}}!