SlusserLabs.AnglePlates 1.1.0-ci.36

This is a prerelease version of SlusserLabs.AnglePlates.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package SlusserLabs.AnglePlates --version 1.1.0-ci.36
                    
NuGet\Install-Package SlusserLabs.AnglePlates -Version 1.1.0-ci.36
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SlusserLabs.AnglePlates" Version="1.1.0-ci.36">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SlusserLabs.AnglePlates" Version="1.1.0-ci.36" />
                    
Directory.Packages.props
<PackageReference Include="SlusserLabs.AnglePlates">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SlusserLabs.AnglePlates --version 1.1.0-ci.36
                    
#r "nuget: SlusserLabs.AnglePlates, 1.1.0-ci.36"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SlusserLabs.AnglePlates@1.1.0-ci.36
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SlusserLabs.AnglePlates&version=1.1.0-ci.36&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SlusserLabs.AnglePlates&version=1.1.0-ci.36&prerelease
                    
Install as a Cake Tool

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 &amp; Grace!</h1>
<p>Welcome!</p>

The string Ada & Grace is rendered as Ada &amp; 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.Encoder controls the encoder to use for text output; the default is HtmlEncoder.Default; null turns encoding off.
  • TemplateOptions.Culture controls the culture used when the renderer is converting objects to string; the default is CultureInfo.InvariantCulture.
  • TemplateOptions.NullVariable controls what is rendered when a variable evaluates to null; 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

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.

There are no supported framework assets in this package.

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