HatTrick.Text.Templating 3.0.0

Prefix Reserved
dotnet add package HatTrick.Text.Templating --version 3.0.0
                    
NuGet\Install-Package HatTrick.Text.Templating -Version 3.0.0
                    
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="HatTrick.Text.Templating" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HatTrick.Text.Templating" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="HatTrick.Text.Templating" />
                    
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 HatTrick.Text.Templating --version 3.0.0
                    
#r "nuget: HatTrick.Text.Templating, 3.0.0"
                    
#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 HatTrick.Text.Templating@3.0.0
                    
#: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=HatTrick.Text.Templating&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=HatTrick.Text.Templating&version=3.0.0
                    
Install as a Cake Tool

HatTrick.Text.Templating

NuGet License: Apache-2.0

A small, allocation-conscious text templating engine for .NET.

Full documentation | hattricklabs.com


Installation

The package targets net9.0.

dotnet add package HatTrick.Text.Templating
using HatTrick.Text.Templating;

Quick Start

var fullName = new { FirstName = "John", LastName = "Doe" };

string template = "Hello {FirstName} {LastName}, this is just a test.";

TemplateEngine ngin = new TemplateEngine(template);

string result = ngin.Merge(fullName);

//result = Hello John Doe, this is just a test.

Features

  • Simple {tag} and compound bind-expression ({Name.First}) replacement
  • Conditional blocks ({#if}) and iteration blocks ({#each}) with falsy-value rules
  • Scope shifting ({#with}) and backward scope-chain walks (..\)
  • Local variable declaration, reassignment, and block-scoped lifetime ({?var:}, {?:}, {:name})
  • Partial template injection ({>tag}) for composable sub-templates
  • Lambda expression calls for formatting, sorting, joining, and custom logic
  • Whitespace control (-/+ trim markers) and a debug tag ({@}) for trace-based troubleshooting
  • A MergeException with line/column/char-index context for precise error location

See the full documentation for all of the above in depth.


License

Apache-2.0 — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on HatTrick.Text.Templating:

Package Downloads
HatTrick.CommandLine

HatTrick Labs command line interface tools.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 182 6/20/2026
2.2.0 1,034 10/3/2022
2.1.3 2,911 4/15/2021
2.1.2 815 3/1/2021
2.1.1 942 12/4/2020
2.1.0 754 10/12/2020
2.0.0 692 10/6/2020
1.1.1 687 9/9/2020
1.1.0 700 8/7/2020
1.0.2 1,234 6/12/2019
1.0.1 798 6/12/2019
1.0.0 1,091 12/21/2018

Breaking: numeric literals in templates no longer require or support a type-suffix postfix.
Allocation-reduction pass across the parser/merge pipeline: char-buffer based tag building, cached compiled lambda invokers (no more dynamic invoke), and hot-path optimizations for simple-tag binding.
Added TemplateStackDepthException with richer MergeException context (start-block tag tracking) for clearer error locations.
Fixed: lambda registration could throw before the intended duplicate-key exception.
Fixed: debug tag misidentified when adjacent to whitespace trim markers (#62).
Lambda argument parsing now accepts null for nullable parameter types.
Upgraded target framework to net9.0.