A simple template engine for .NET.
To get started, you can install the package from NuGet.
dotnet add package DevantlerTech.TemplateEngine
Note
The template engine uses Scriban under the hood. So to learn more about the syntax, you can visit the Scriban documentation.
To render a template, you can use the Generator
class or the TemplateEngine
class directly.
using DevantlerTech.TemplateEngine;
var templateEngine = new TemplateEngine();
var generator = new Generator(templateEngine);
var template = "Hello, {{name}}!"; // or "/path/to/template"
var model = new { Name = "World" };
string resultFromEngine = templateEngine.Render(template, model);
string resultFromGenerator = await generator.GenerateAsync(template, model);
You can also generate a file from a template.
using DevantlerTech.TemplateEngine;
var generator = new Generator(new TemplateEngine());
var template = "Hello, {{name}}!"; // or "/path/to/template"
var model = new { Name = "World" };
var outputPath = "hello.txt";
await generator.GenerateAsync(outputPath, template, model);
Both of these scenarios will render Hello, World!
as the output, since the name
property is set to World
, and the template is Hello, {{name}}!
.