pub struct Parser { /* private fields */ }
Implementations§
source§impl Parser
impl Parser
pub fn new() -> Self
sourcepub fn parse(&self, text: &str) -> Result<Template>
pub fn parse(&self, text: &str) -> Result<Template>
Parses a liquid template, returning a Template object.
Examples
Minimal Template
let template = liquid::ParserBuilder::with_stdlib()
.build().unwrap()
.parse("Liquid!").unwrap();
let globals = liquid::Object::new();
let output = template.render(&globals).unwrap();
assert_eq!(output, "Liquid!".to_string());
sourcepub fn parse_file<P: AsRef<Path>>(&self, file: P) -> Result<Template>
pub fn parse_file<P: AsRef<Path>>(&self, file: P) -> Result<Template>
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_stdlib()
.build().unwrap()
.parse_file("path/to/template.txt").unwrap();
let globals = liquid::object!({
"data": 4f64,
});
let output = template.render(&globals).unwrap();
assert_eq!(output, "Liquid! 4\n".to_string());
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl !UnwindSafe for Parser
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more