ASTTemplateParser 2.0.3
dotnet add package ASTTemplateParser --version 2.0.3
NuGet\Install-Package ASTTemplateParser -Version 2.0.3
<PackageReference Include="ASTTemplateParser" Version="2.0.3" />
<PackageVersion Include="ASTTemplateParser" Version="2.0.3" />
<PackageReference Include="ASTTemplateParser" />
paket add ASTTemplateParser --version 2.0.3
#r "nuget: ASTTemplateParser, 2.0.3"
#:package ASTTemplateParser@2.0.3
#addin nuget:?package=ASTTemplateParser&version=2.0.3
#tool nuget:?package=ASTTemplateParser&version=2.0.3
AST Template Parser
A high-performance, security-hardened template parser for .NET with HTML-like syntax. Works on .NET Standard 2.0, .NET Framework 4.8, .NET 6.0, and .NET 8.0.
โจ Features
- ๐ High Performance - 90,000+ renders/second with compiled property accessors.
- ๐ Enterprise Security - Built-in XSS protection, loop limits, and property whitelisting.
- ๐งฉ Component System - Reusable
<Element>,<Block>,<Data>, and<Nav>components. - ๐ Layout System - Master page layouts with sections and slots.
- ๐ Auto Cache - AST and component files automatically reload when modified.
- ๐ฏ Indexer Support - Access arrays and dictionaries:
{{ items[0] }}(v2.0.1+). - ๐งช Template Filters - Transform data with pipes:
{{ Name | uppercase }}(v2.0.3+). - ๐ Template Fragments -
<Define>and<Render>for inline recursion and menus. - ๐ Global Variables - Set static variables once for all engine instances.
- ๐ Cross-Platform - Fully compatible with Windows, Linux, and macOS.
๐ฆ Installation
NuGet Package Manager:
Install-Package ASTTemplateParser
.NET CLI:
dotnet add package ASTTemplateParser
๐ Quick Start (5 Minutes)
Step 1: Create the Engine
using ASTTemplateParser;
var engine = new TemplateEngine();
Step 2: Set Your Data
engine.SetVariable("UserName", "Antigravity");
engine.SetVariable("Products", new List<object> {
new { Name = "Laptop", Price = 999.99 },
new { Name = "Mouse", Price = 29.99 }
});
Step 3: Write Template & Render
<h1>Welcome, {{UserName}}!</h1>
<ul>
<ForEach var="p" in="Products">
<li>{{p.Name}} - {{p.Price | currency:"en-US"}}</li>
</ForEach>
</ul>
string html = engine.Render(template);
๐ Template Syntax Guide
1. Variables & Accessors
Supports simple variables, nested properties, and indexers.
{{Name}}
{{User.Address.City}}
{{Items[0].Title}}
{{Meta["version"]}}
2. Template Filters (NEW in v2.0.3)
Transform data using the pipe (|) syntax.
| Filter | Usage Example | Output |
|---|---|---|
uppercase |
{{ Name | uppercase }} |
NAME |
lowercase |
{{ Name | lowercase }} |
name |
date |
{{ Created | date:"dd MMM yyyy" }} |
21 Jan 2026 |
currency |
{{ Price | currency:"bn-BD" }} |
1,250.75เงณ |
Custom Filters:
TemplateEngine.RegisterFilter("shout", (val, args) => val?.ToString() + "!!!");
3. Conditionals (If/Else)
<If condition="IsLoggedIn">
<p>Welcome back!</p>
<ElseIf condition="Role == 'admin'">
<p>Admin Dashboard</p>
<Else>
<p>Please log in</p>
</If>
4. Loops (ForEach)
<ForEach var="item" in="Items">
<li>{{item.Name}}</li>
</ForEach>
5. Components & Tags
Instead of generic includes, use type-specific tags for auto-path resolution:
| Tag | Directory Prefix | Example |
|---|---|---|
<Element> |
element/ |
<Element component="button"> |
<Block> |
block/ |
<Block component="hero"> |
<Data> |
data/ |
<Data component="meta"> |
<Nav> |
navigation/ |
<Nav component="menu"> |
๐ Security Configuration
The parser is hardened by default, but you can customize it:
var security = new SecurityConfig {
MaxLoopIterations = 500, // DoS protection
MaxRecursionDepth = 5, // StackOverflow protection
HtmlEncodeOutput = true, // XSS protection
BlockedPropertyNames = new HashSet<string> { "Password", "Secret" }
};
var engine = new TemplateEngine(security);
๐ Performance Metrics
| Scenario | Operations / Second |
|---|---|
| Simple Template Rendering | ~90,000+ ops/sec |
| Complex Component Rendering | ~6,500+ ops/sec |
| Property Access (Compiled) | ~12,000,000+ ops/sec |
Tested on .NET 8.0 / Intel i7 / Windows 11.
๐งช Global & Local Callbacks
Global Variables
Perfect for site-wide settings like SiteName or CopyrightYear.
TemplateEngine.SetGlobalVariable("Year", 2026);
OnBeforeIncludeRender
Fires before each component renders. Use it to inject dynamic data based on component name.
engine.OnBeforeIncludeRender((info, eng) => {
var data = Database.Fetch(info.Name);
eng.SetVariable("item", data);
});
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.8
- NCalc.NetCore (>= 1.0.1)
-
.NETStandard 2.0
- NCalc.NetCore (>= 1.0.1)
-
net6.0
- NCalc.NetCore (>= 1.0.1)
-
net8.0
- NCalc.NetCore (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.3 | 70 | 1/21/2026 |
| 2.0.2 | 72 | 1/20/2026 |
| 2.0.0 | 81 | 1/20/2026 |
| 1.0.45 | 93 | 1/19/2026 |
| 1.0.43 | 83 | 1/19/2026 |
| 1.0.42 | 78 | 1/19/2026 |
| 1.0.41 | 80 | 1/19/2026 |
| 1.0.40 | 80 | 1/19/2026 |
| 1.0.39 | 92 | 1/17/2026 |
| 1.0.38 | 76 | 1/15/2026 |
| 1.0.37 | 86 | 1/15/2026 |
| 1.0.36 | 88 | 1/15/2026 |
| 1.0.35 | 82 | 1/15/2026 |
| 1.0.33 | 81 | 1/14/2026 |
| 1.0.32 | 76 | 1/14/2026 |
| 1.0.31 | 88 | 1/14/2026 |
| 1.0.30 | 88 | 1/14/2026 |
| 1.0.29 | 100 | 1/14/2026 |
| 1.0.28 | 86 | 1/14/2026 |
| 1.0.27 | 91 | 1/14/2026 |
| 1.0.26 | 80 | 1/13/2026 |
| 1.0.25 | 84 | 1/13/2026 |
| 1.0.24 | 78 | 1/13/2026 |
| 1.0.23 | 76 | 1/13/2026 |
| 1.0.22 | 79 | 1/13/2026 |
| 1.0.21 | 83 | 1/13/2026 |
| 1.0.20 | 83 | 1/13/2026 |
| 1.0.19 | 81 | 1/12/2026 |
| 1.0.18 | 84 | 1/12/2026 |
| 1.0.17 | 86 | 1/12/2026 |
| 1.0.16 | 78 | 1/12/2026 |
| 1.0.15 | 76 | 1/12/2026 |
| 1.0.14 | 84 | 1/12/2026 |
| 1.0.13 | 76 | 1/12/2026 |
| 1.0.12 | 84 | 1/12/2026 |
| 1.0.11 | 83 | 1/11/2026 |
| 1.0.10 | 78 | 1/11/2026 |
| 1.0.9 | 85 | 1/10/2026 |
| 1.0.8 | 84 | 1/10/2026 |
| 1.0.7 | 85 | 1/10/2026 |
| 1.0.6 | 85 | 1/8/2026 |
| 1.0.5 | 85 | 1/8/2026 |
| 1.0.4 | 82 | 1/8/2026 |
| 1.0.3 | 83 | 1/7/2026 |
| 1.0.2 | 84 | 1/7/2026 |
| 1.0.1 | 86 | 1/7/2026 |
| 1.0.0 | 83 | 1/7/2026 |
v2.0.3 - (January 21, 2026)
- ADDED: Template Filters with Pipe syntax (e.g. {{ Name | uppercase }}).
- ADDED: Built-in filters: uppercase, lowercase, date, currency.
- ADDED: Support for Filter Arguments (e.g. {{ Price | currency:"bn-BD" }}).
- ADDED: Custom Filter Registration via TemplateEngine.RegisterFilter().
- IMPROVED: Filter execution performance with cached delegates.
v2.0.2 - (January 20, 2026)
- FIXED: Resolved "Unsafe expression" errors by making SecurityConfig less restrictive by default.
- FIXED: Improved regex for safe characters in expressions (bracket and quote support).
- IMPROVED: Added detailed reason to TemplateSecurityException for easier debugging.
- IMPROVED: Added support for IList and native Array indexing (e.g. item[0]).
- IMPROVED: Exposed Security property on TemplateEngine for instance-level configuration.
v2.0.1 - (January 20, 2026)
- ADDED: High-performance Indexer Support (item[key]).
- ADDED: Compiled delegate caching for indexers for maximum speed.
- ADDED: Support for dynamic key resolution in templates.
- IMPROVED: Expression evaluation robustness.
- SECURITY: Enhanced indexer validation with BlockedPropertyNames.