SlusserLabs.AnglePlates
1.2.0-ci.37
See the version list below for details.
dotnet add package SlusserLabs.AnglePlates --version 1.2.0-ci.37
NuGet\Install-Package SlusserLabs.AnglePlates -Version 1.2.0-ci.37
<PackageReference Include="SlusserLabs.AnglePlates" Version="1.2.0-ci.37"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="SlusserLabs.AnglePlates" Version="1.2.0-ci.37" />
<PackageReference Include="SlusserLabs.AnglePlates"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add SlusserLabs.AnglePlates --version 1.2.0-ci.37
#r "nuget: SlusserLabs.AnglePlates, 1.2.0-ci.37"
#:package SlusserLabs.AnglePlates@1.2.0-ci.37
#addin nuget:?package=SlusserLabs.AnglePlates&version=1.2.0-ci.37&prerelease
#tool nuget:?package=SlusserLabs.AnglePlates&version=1.2.0-ci.37&prerelease
AnglePlates
AnglePlates is a .NET source generator for rendering templates. Think of it like T4 templates for modern .NET.
Templates are created at compile time, do not require reflection, are AOT friendly, yield excellent performance, and you get to use the C# skills you already know instead of learning a specific template language. The compiled templates write synchronously to a TextWriter or an IBufferWriter<byte>. For asynchronous UTF-8 streaming, render to a PipeWriter, such as an HTTP response body.
Quick start
Add the package:
dotnet package add SlusserLabs.AnglePlates
Create a model (or use an object you already have):
namespace MyApp;
public sealed record GreetingModel
{
public string Name { get; init; } = default!;
public string? Message { get; init; }
}
Make a template, e.g. Templates/greeting.html:
#model MyApp.GreetingModel
[* A greeting with an optional message. *]
<h1>Hello, [[ model.Name ]]!</h1>
[% if (!string.IsNullOrEmpty(model.Message)) { %]
<p>[[ model.Message ]]</p>
[% } %]
#model is the only required directive. The Templates/ folder is the default location for processing templates but that is customizable. Documentation of options and the full template syntax are linked below.
Build, then render the generated class. In a project whose RootNamespace is MyApp, the source generator will have created a type named MyApp.Templates.GreetingTextTemplate with a default instance for you to pass your model to and render:
using MyApp;
using MyApp.Templates;
using SlusserLabs.AnglePlates;
var model = new GreetingModel { Name = "Ada & Grace", Message = "Welcome!" };
string html = GreetingTextTemplate.Default.RenderToString(model);
Output (blank lines omitted):
<h1>Hello, Ada & Grace!</h1>
<p>Welcome!</p>
The string Ada & Grace is rendered as Ada & Grace because variable output is HTML-encoded to protect against Cross-Site Scripting (XSS). Options exist of course to customize or disable this behavior.
Rendering and options
Each template generates a *TextTemplate class for TextWriter and a *Utf8Template class for IBufferWriter<byte>. The UTF-8 class also has RenderAsync for easy PipeWriter usage, including ASP.NET Core's HttpResponse.BodyWriter.
Use the static Default for a shared instance, or pass options to the constructor:
var email = new GreetingTextTemplate(new TemplateOptions { Encoder = null });
var german = new GreetingTextTemplate(new TemplateOptions
{
Culture = System.Globalization.CultureInfo.GetCultureInfo("de-DE")
});
TemplateOptions.Encodercontrols the encoder to use for text output; the default isHtmlEncoder.Default;nullturns encoding off.TemplateOptions.Culturecontrols the culture used when the renderer is converting objects to string; the default isCultureInfo.InvariantCulture.TemplateOptions.NullVariablecontrols what is rendered when a variable evaluates tonull; the default is nothing.
Samples
Both samples are small runnable .NET 10 programs. Each has a README with a run command and expected output:
- HelloWorld: render a Markdown greeting and numbered task list with conditions and a loop.
- HelloWorldApi: stream a UTF-8 HTML page with nested models, a child template, and default encoding.
Learn more
- Template reference: directives, syntax, child templates, rendering, and MSBuild settings.
- Glossary: template terminology, generation, and rendering.
- Diagnostics: build errors and their fixes.
- Contributing and development: build, test, and release commands.
Templates are trusted C# source. Only compile templates you'd trust as part of your application.
AI Disclosure
This project was built with the help of AI. As with any tool I use for coding, I am fully responsible for the end result and only put forward this project with full confidence that I have reviewed every line. Whether a line of code in this project was fully AI generated, AI assisted, or entirely from my own Muppet fingers on the keyboard, it is held to the same expectations.
License
AnglePlates is released under the MIT License.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.0-ci.38 | 0 | 10/26/2026 |
| 1.2.0-ci.37 | 3 | 10/24/2026 |
| 1.1.0-ci.36 | 0 | 10/24/2026 |
| 1.1.0-ci.35 | 0 | 10/24/2026 |
| 1.1.0-ci.34 | 0 | 10/24/2026 |
| 1.1.0-beta.33.1 | 0 | 10/23/2026 |
| 1.1.0-beta.1.1 | 0 | 10/23/2026 |