#templating #string #instance #replacing #renders #pair

bin+lib nanotemplate

A minimal templating engine that renders a string from the template, replacing all instances of {placeholder} with given values

4 releases (2 breaking)

0.3.0 Sep 22, 2022
0.2.1 Jun 23, 2021
0.2.0 May 5, 2021
0.1.0 May 4, 2021

#131 in Template engine

Download history 567/week @ 2024-06-14 537/week @ 2024-06-21 602/week @ 2024-06-28 463/week @ 2024-07-05 821/week @ 2024-07-12 4544/week @ 2024-07-19 494/week @ 2024-07-26 696/week @ 2024-08-02 654/week @ 2024-08-09 597/week @ 2024-08-16 665/week @ 2024-08-23 653/week @ 2024-08-30 1683/week @ 2024-09-06 2902/week @ 2024-09-13 2438/week @ 2024-09-20 1159/week @ 2024-09-27

8,366 downloads per month
Used in 2 crates

MIT license

17KB
298 lines

Latest Version Documentation License

A minimal templating engine that renders a string from the template, replacing all instances of {placeholder} with given values.

The engine is strict:

  • all placeholders must have values provided (use template_default to use default value for placeholders),
  • all provided values must have matching placeholder (when using template_strict),
  • a single placeholder can be used multiple times and will be expanded in all places.

Values are provided as an iterable object that provides placeholder name and value pairs.

use nanotemplate::template;

assert_eq!(
	template("Hello, my name is {name}!", &[("name", "nanotemplate")]).unwrap(),
	"Hello, my name is nanotemplate!".to_owned());

Also comes with simple CLI utility:

echo "Hello my name is {name}" | nanotemplate name=nanotemplate

No runtime deps