11 releases (7 breaking)

2.0.0 Aug 2, 2020
1.0.0 Feb 13, 2020
0.8.1 Oct 15, 2022
0.4.1 Jul 13, 2022
0.2.0 Feb 11, 2020

#232 in Template engine

Download history 1/week @ 2024-02-14 15/week @ 2024-02-21 2/week @ 2024-02-28 1/week @ 2024-03-13 66/week @ 2024-03-27 76/week @ 2024-04-03

142 downloads per month

ISC license

27KB
838 lines

bempline

A simple template engine for simple things.

Syntax

Variables are alphanumeric strings (underscores, too) surrounded by braces. Here's an {example}.

You can prevent {word} from being seen as a variable by escaping the opening brace. Like \{this}.

Example

If you have this document in something like template.bpl

Dear {name},

Some generic email text here!

Sincerely,
Some Company

You can fill it out for the names Ferris and Rusty like so

use bempline::Document;

fn main() {
	let doc = Document::from_file("test/template.bpl").unwrap();
	let names = vec!["Ferris", "Rusty"];

	for name in names {
		let mut cloned = doc.clone();
		cloned.set("name", name);
		
		println!("{}", cloned.compile());
	}
}

lib.rs:

Syntax

Variables are alphanumeric strings (underscores, too) surrounded by braces. Here's an {example}.

You can prevent {word} from being seen as a variable by escaping the opening brace. Like \{this}.

Example

If you have this document in something like template.bpl

Dear {name},

Some generic email text here!

Sincerely,
Some Company

You can fill it out for the names Ferris and Rusty like so

use bempline::{Document, Options};

fn main() {
	let doc = Document::from_file("test/template.bpl", Options::default()).unwrap();
	let names = vec!["Ferris", "Rusty"];

	for name in names {
		let mut cloned = doc.clone();
		cloned.set("name", name);

		println!("{}", cloned.compile());
	}
}

No runtime deps