Plinth.Templating
1.7.4
Prefix Reserved
See the version list below for details.
dotnet add package Plinth.Templating --version 1.7.4
NuGet\Install-Package Plinth.Templating -Version 1.7.4
<PackageReference Include="Plinth.Templating" Version="1.7.4" />
<PackageVersion Include="Plinth.Templating" Version="1.7.4" />
<PackageReference Include="Plinth.Templating" />
paket add Plinth.Templating --version 1.7.4
#r "nuget: Plinth.Templating, 1.7.4"
#:package Plinth.Templating@1.7.4
#addin nuget:?package=Plinth.Templating&version=1.7.4
#tool nuget:?package=Plinth.Templating&version=1.7.4
README
Plinth.Templating
HTML Templating library for generating emails and documents
1. Create an assembly with your cshtml templates in it, and some models
Directory structure example for a template assembly:
Templates/
Email1.cshtml
Email2.cshtml
Email3.cshtml
Layouts/
DefaultEmail.cshtml
Shared/
ButtonLink.cshtml
Models/
EmailModel.cs
2. Initialize the engine
var engine = new TemplateEngineBuilder()
.AddTemplateAssembly(typeof(EmailModel).Assembly, new[] { "Layouts", "Shared", "Templates" })
.PrecompileInBackground() // optional
.Build();
👉 the paths given are optional. If none are given then you must specify the full path from the assembly root
Example, with no paths, specify "Templates/Email1"
with "Templates" specified, "Email1" will work as well
👉 This goes for references in your code to templates, as well as Layouts, Partials, and IncludeAsync's
👉 The root of the assembly is always included
3. Set up templates
⚠️ NOTE! NOTE! NOTE! 👉 Make sure your cshtml files are set to "Embedded Resource" in your .csproj
@using MyAssembly.Models // using directives work just like c#
@inherits Plinth.Templating.Template<EmailModel> // do this to enable Include functionality
@inherits Plinth.Templating.Template // if not using a model
@model EmailModel // set up your model
@{ Layout = "DefaultEmail"; } // optionally, set up a Layout
@{ await IncludeAsync("ButtonLink", Model.Link); } // example of including another template
<p>@Model.Title</p> // example of using the model
<p>@ViewBag.Subtitle</p> // example of using the view bag
@functions { // static functions
public static int Double(int x) => x * 2;
}
@{ // local functions (can access model and viewbag)
int Double() => Model.Number * 2;
}
4. Render your templates
// no model
var result = await engine.RenderAsync("Email1");
// with model
var emailModel = new EmailModel { ... }
var result = await engine.RenderAsync("Email1", emailModel);
// with viewbag
dynamic viewbag = new ExpandoObject();
viewbag.Field1 = 7;
var result = await engine.RenderWithViewBagAsync("Email1", viewbag);
// with model and viewbag
var emailModel = new EmailModel { ... }
dynamic viewbag = new ExpandoObject();
viewbag.Field1 = 7;
var result = await engine.RenderWithViewBagAsync("Email1", emailModel, viewbag);
5. Rendering dynamic templates from strings
You can render a string template and cache it for later use, or for one time use
👉 These following are cached by "TemplateKey1", and re-rendering with that same key will ignore the string template subsequent renders
// no model
var result = await engine.RenderRawAsync("TemplateKey1", "<div>Hello</div>");
// with model
var emailModel = new EmailModel { ... }
var result = await engine.RenderRawAsync("TemplateKey1",
"<div>@Model.Name</div>", emailModel);
// with viewbag
dynamic viewbag = new ExpandoObject();
viewbag.Field1 = 7;
var result = await engine.RenderRawWithViewBagAsync("TemplateKey1",
"<div>@ViewBag.Field1</div>", viewbag);
// with model and viewbag
var emailModel = new EmailModel { ... }
dynamic viewbag = new ExpandoObject();
viewbag.Field1 = 7;
var result = await engine.RenderRawWithViewBagAsync("TemplateKey1",
"<div>@Model.Name, @ViewBag.Field1</div>", emailModel, viewbag);
👉 The following are one-offs and will re-compile every time
// no model
var result = await engine.RenderRawOnceAsync("<div>Hello</div>");
// with model
var emailModel = new EmailModel { ... }
var result = await engine.RenderRawOnceAsync("<div>@Model.Name</div>", emailModel);
// with viewbag
dynamic viewbag = new ExpandoObject();
viewbag.Field1 = 7;
var result = await engine.RenderRawOnceWithViewBagAsync(
"<div>@ViewBag.Field1</div>", viewbag);
// with model and viewbag
var emailModel = new EmailModel { ... }
dynamic viewbag = new ExpandoObject();
viewbag.Field1 = 7;
var result = await engine.RenderRawOnceWithViewBagAsync(
"<div>@Model.Name, @ViewBag.Field1</div>", emailModel, viewbag);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
-
net6.0
- Microsoft.SourceLink.Bitbucket.Git (>= 1.1.1)
- Plinth.Common (>= 1.7.4)
- RazorLight (>= 2.3.1)
- System.Text.Json (>= 9.0.7)
-
net8.0
- Microsoft.SourceLink.Bitbucket.Git (>= 1.1.1)
- Plinth.Common (>= 1.7.4)
- RazorLight (>= 2.3.1)
- System.Text.Json (>= 9.0.7)
-
net9.0
- Microsoft.SourceLink.Bitbucket.Git (>= 1.1.1)
- Plinth.Common (>= 1.7.4)
- RazorLight (>= 2.3.1)
- System.Text.Json (>= 9.0.7)
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 |
|---|---|---|
| 1.8.1 | 519 | 12/11/2025 |
| 1.8.0 | 313 | 11/13/2025 |
| 1.8.0-b211.72089fd9 | 247 | 11/12/2025 |
| 1.7.4 | 431 | 8/6/2025 |
| 1.7.3 | 130 | 8/2/2025 |
| 1.7.2 | 1,148 | 3/16/2025 |
| 1.7.1 | 566 | 12/12/2024 |
| 1.7.0 | 3,291 | 11/12/2024 |
| 1.6.6 | 803 | 11/8/2024 |
| 1.6.5 | 3,196 | 8/31/2024 |
| 1.6.4 | 613 | 8/2/2024 |
| 1.6.3 | 728 | 5/15/2024 |
| 1.6.2 | 504 | 2/16/2024 |
| 1.6.1 | 5,235 | 1/5/2024 |
| 1.6.0 | 1,250 | 11/30/2023 |
| 1.5.10-b186.aca976b4 | 161 | 11/30/2023 |
| 1.5.9 | 243 | 11/29/2023 |
| 1.5.9-b174.64153841 | 280 | 11/23/2023 |
| 1.5.9-b172.dfc6e7bd | 254 | 11/17/2023 |
| 1.5.9-b171.4e2b92e2 | 450 | 11/4/2023 |
net9.0 support