Struct liquid::Parser
[−]
[src]
pub struct Parser { /* fields omitted */ }
Methods
impl Parser
[src]
pub fn new() -> Self
[src]
pub fn parse(&self, text: &str) -> Result<Template>
[src]
Parses a liquid template, returning a Template object.
Examples
Minimal Template
let template = liquid::ParserBuilder::with_liquid() .build() .parse("Liquid!").unwrap(); let globals = liquid::Object::new(); let output = template.render(&globals).unwrap(); assert_eq!(output, "Liquid!".to_string());
pub fn parse_file<P: AsRef<Path>>(self, file: P) -> Result<Template>
[src]
Parse a liquid template from a file, returning a Result<Template, Error>
.
Examples
Minimal Template
template.txt
:
"Liquid {{data}}"
Your rust code:
let template = liquid::ParserBuilder::with_liquid() .build() .parse_file("path/to/template.txt").unwrap(); let mut globals = liquid::Object::new(); globals.insert("data".to_owned(), liquid::Value::scalar(4f32)); let output = template.render(&globals).unwrap(); assert_eq!(output, "Liquid! 4\n".to_string());