mustache2 1.0.7

Logic-less templates.
Documentation
//! This example showcases the inheritance extension of the Mustache spec.
//! It requires the `ext-inheritance` feature flag to work.

use std::collections::HashMap;

use mustache2::{
    Data,
    render::{RenderManager, SourceCache, provider::StaticProvider},
};

pub fn main() {
    let cache = SourceCache::default();
    let mut renderer = RenderManager::new(
        // You can use `FsProvider` to read files off the disk.
        StaticProvider(HashMap::from([
            (
                "root",
                r#"
{{<parent}}
    {{$name}}Mustache{{/name}}
{{/parent}}"#,
            ),
            ("parent", "Hello, {{$name}}World{{/name}}!"),
        ])),
        &cache,
    );
    let mut out = String::new();

    // Render the parent template, using the default value for $name.
    if let Err(e) = renderer.render_to(&mut out, "parent", Data::Null) {
        renderer.display_error(e);
        return;
    }

    // Render the root template, which replaces $name with "Mustache".
    if let Err(e) = renderer.render_to(&mut out, "root", Data::Null) {
        renderer.display_error(e);
        return;
    }

    assert_eq!(out, "Hello, World!\nHello, Mustache!");
}