liquid/
partials.rs

1//! ## Using partials
2//!
3//! To use `{% include %}` or `{% render %}` tags in a template, you first need to compile these
4//! included files as template partials.
5//!
6//! Example:
7//!
8//! ```liquid
9//! # common.liquid
10//! Number: {{ i }}
11//! ```
12//!
13//! ```rust
14//! use liquid::ParserBuilder;
15//! use liquid::partials::{EagerCompiler, InMemorySource, PartialSource};
16//!
17//! // Build template partials using an eager, in-memory source compiler.
18//! // Other compilation policies also exist depending on specific needs.
19//! type Partials = EagerCompiler<InMemorySource>;
20//!
21//! let partials = {
22//!   let mut partials = Partials::empty();
23//!
24//!   let filepath = String::from("common.liquid");
25//!   //let contents = std::fs::read_to_string(&filepath).unwrap();
26//!   let contents = "Number: {{ i }}";
27//!
28//!   partials.add(filepath, contents);
29//!   partials
30//! };
31//!
32//! // Compile and render the main template, which uses the "common" partial.
33//! let parser = ParserBuilder::with_stdlib().partials(partials).build().unwrap();
34//! let rendered = {
35//!     let globals = liquid::object!({ "num": 42 });
36//!     parser
37//!         .parse("Liquid! {% render \"common\", i: num %}").unwrap()
38//!         .render(&globals).unwrap()
39//! };
40//!
41//! assert_eq!(rendered, "Liquid! Number: 42");
42//! ```
43
44pub use liquid_core::partials::*;