Plinth.Templating 1.5.9-b172.dfc6e7bd

Prefix Reserved
This is a prerelease version of Plinth.Templating.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Plinth.Templating --version 1.5.9-b172.dfc6e7bd
                    
NuGet\Install-Package Plinth.Templating -Version 1.5.9-b172.dfc6e7bd
                    
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="Plinth.Templating" Version="1.5.9-b172.dfc6e7bd" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Plinth.Templating" Version="1.5.9-b172.dfc6e7bd" />
                    
Directory.Packages.props
<PackageReference Include="Plinth.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 Plinth.Templating --version 1.5.9-b172.dfc6e7bd
                    
#r "nuget: Plinth.Templating, 1.5.9-b172.dfc6e7bd"
                    
#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 Plinth.Templating@1.5.9-b172.dfc6e7bd
                    
#: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=Plinth.Templating&version=1.5.9-b172.dfc6e7bd&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Plinth.Templating&version=1.5.9-b172.dfc6e7bd&prerelease
                    
Install as a Cake Tool

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 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 is compatible.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.7.4 224 8/6/2025
1.7.3 45 8/2/2025
1.7.2 645 3/16/2025
1.7.1 490 12/12/2024
1.7.0 555 11/12/2024
1.6.6 705 11/8/2024
1.6.5 2,478 8/31/2024
1.6.4 523 8/2/2024
1.6.3 635 5/15/2024
1.6.2 414 2/16/2024
1.6.1 4,597 1/5/2024
1.6.0 1,187 11/30/2023
1.5.10-b186.aca976b4 120 11/30/2023
1.5.9 186 11/29/2023
1.5.9-b174.64153841 251 11/23/2023
1.5.9-b172.dfc6e7bd 225 11/17/2023
1.5.9-b171.4e2b92e2 402 11/4/2023
1.5.8 482 10/23/2023
1.5.7 7,963 7/31/2023
1.5.6 1,747 7/13/2023
1.5.5 247 6/29/2023
1.5.4 1,056 3/7/2023
1.5.3 313 3/3/2023
1.5.2 426 1/11/2023
1.5.2-b92.7c961f5f 179 1/11/2023
1.5.0 597 11/9/2022
1.5.0-b88.7a7c20cd 170 11/9/2022
1.4.7 2,379 10/20/2022
1.4.6 681 10/17/2022
1.4.5 698 10/1/2022
1.4.4 558 8/16/2022
1.4.3 519 8/2/2022
1.4.2 516 7/19/2022
1.4.2-b80.7fdbfd04 209 7/19/2022
1.4.2-b74.acaf86f5 196 6/15/2022
1.4.1 542 6/13/2022
1.4.0 525 6/6/2022
1.3.8 932 4/12/2022
1.3.7 608 3/21/2022
1.3.6 577 3/17/2022
1.3.6-b67.ca5053f3 221 3/16/2022
1.3.6-b66.4a9683e6 215 3/16/2022
1.3.5 555 2/23/2022
1.3.4 869 1/20/2022
1.3.3 441 12/29/2021
1.3.2 563 12/11/2021
1.3.1 465 11/12/2021
1.3.0 428 11/8/2021
1.2.3 1,622 9/22/2021
1.2.2 820 8/20/2021
1.2.1 825 8/5/2021
1.2.0 586 8/1/2021
1.2.0-b37.a54030b9 253 6/24/2021
1.1.6 1,926 3/22/2021
1.1.5 474 3/9/2021
1.1.4 601 2/27/2021
1.1.3 499 2/17/2021
1.1.2 484 2/12/2021
1.1.1 816 2/1/2021
1.1.0 616 12/16/2020
1.1.0-b27.b66c309b 383 11/15/2020
1.0.12 1,286 10/18/2020
1.0.11 605 10/6/2020
1.0.10 557 9/30/2020
1.0.9 558 9/29/2020
1.0.8 767 9/26/2020
1.0.7 711 9/19/2020
1.0.6 598 9/3/2020
1.0.5 883 9/2/2020
1.0.4 794 9/1/2020
1.0.3 637 9/1/2020
1.0.2 653 8/29/2020
1.0.1 647 8/29/2020
1.0.0 616 8/29/2020
1.0.0-b1.c22f563d 343 8/28/2020

net7.0 support and removed netcoreapp3.1