https://github.com/devantler-tech/dotnet-template-engine
A simple template engine for .NET. Built with Scriban.
https://github.com/devantler-tech/dotnet-template-engine
library
Last synced: 3 months ago
JSON representation
A simple template engine for .NET. Built with Scriban.
- Host: GitHub
- URL: https://github.com/devantler-tech/dotnet-template-engine
- Owner: devantler-tech
- License: apache-2.0
- Created: 2024-07-07T21:07:48.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-11-25T11:41:43.000Z (4 months ago)
- Last Synced: 2025-11-28T17:31:28.245Z (4 months ago)
- Topics: library
- Language: C#
- Size: 245 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# 📄 .NET Template Engine
[](https://opensource.org/licenses/Apache-2.0)
[](https://github.com/devantler-tech/dotnet-template-engine/actions/workflows/test.yaml)
[](https://codecov.io/gh/devantler-tech/dotnet-template-engine)
A simple template engine for .NET.
## 🚀 Getting Started
To get started, you can install the package from NuGet.
```bash
dotnet add package DevantlerTech.TemplateEngine
```
## 📝 Usage
> [!NOTE]
> The template engine uses [Scriban](https://github.com/scriban/scriban) under the hood. So to learn more about the syntax, you can visit the [Scriban documentation](https://github.com/scriban/scriban/blob/master/doc/language.md).
To render a template, you can use the `Generator` class or the `TemplateEngine` class directly.
```csharp
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.
```csharp
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}}!`.