![]() |
VOOZH | about |
dotnet add package Rocketmakers.Templates.Handlebars --version 0.2.3
NuGet\Install-Package Rocketmakers.Templates.Handlebars -Version 0.2.3
<PackageReference Include="Rocketmakers.Templates.Handlebars" Version="0.2.3" />
<PackageVersion Include="Rocketmakers.Templates.Handlebars" Version="0.2.3" />Directory.Packages.props
<PackageReference Include="Rocketmakers.Templates.Handlebars" />Project file
paket add Rocketmakers.Templates.Handlebars --version 0.2.3
#r "nuget: Rocketmakers.Templates.Handlebars, 0.2.3"
#:package Rocketmakers.Templates.Handlebars@0.2.3
#addin nuget:?package=Rocketmakers.Templates.Handlebars&version=0.2.3Install as a Cake Addin
#tool nuget:?package=Rocketmakers.Templates.Handlebars&version=0.2.3Install as a Cake Tool
A library for rendering content using templates from an external source and including dynamic data.
This is the core library used by implementations that includes core types and interfaces.
This library contains an implementation for ITemplateService, whose purpose is to obtain the templates from a Http source. An in memory cache is also provided to support caching template content to avoid over-fetching.
This library contains an implemention for ITemplateRenderer, providing the ability to render templates using Handlerbars.JS.
This assumes you have setup and configured your template repo.
The first thing you'll want to do is configure your TemplateService. For templates stored at a remote source, we'll be using Rocketmakers.Templates.Http.
This can be setup using the following snippet.
// Initialise the template service
var templateService = new HttpTemplateService(
repository: new AnonTemplateRepository(
new HttpClient { BaseAddress = "https://gitlab.com/my-org/my-templates/-/raw/develop/" }
),
cache: new InMemoryTemplateContentCache(
new InMemoryTemplateContentCacheConfig(
UseCache: true,
CacheExpirySeconds: 3600
)
)
);
If you are utilising the default .NET dependency injection, then you can set it up as follows
// Inject service into Microsoft.Extensions.DependencyInjection.IServiceCollection
services.AddHttpTemplateService(
repositoryUrl: new Uri("https://gitlab.com/my-org/my-templates/-/raw/develop/"),
cacheConfig: new InMemoryTemplateContentCacheConfig(
UseCache: true,
CacheExpirySeconds: 3600
)
);
You'll also want to register your ITemplateRenderer implementation. In our example, we'll be using Rocketmakers.Templates.Handlebars for processing handlerbars based templates.
services.AddSingleton<ITemplateRenderer, HandleBarsTemplateRenderer>();
Retrieving templates is done in the following way. You will repeat the following process for each service whose templates you want to setup.
// Maps to 'myService.json' in the source containing your templates. This is what contains the
// metadata describing the location of the layouts and partials comprising your templates
var serviceName = "myService";
// Get the latest templates for your service
TemplateGroup templateGroup = await templateService.GetTemplatesAsync(serviceName);
// Update the renderer with the latest templates
await renderer.UpdateTemplateGroupAsync(templateGroup);
There are two ways you can setup the above, and which one you use will depend on where you want to compromise.
You can update the templates on bootstrap of your application. This means that rendering templates will be quick as they won't need to be downloaded and compiled. However startup time of your application will be slower. This will be benefical for services that are active for a long time, but not very handy for services that scale to zero or you need to start up quickly.
You can update the templates everytime you render them. This means that startup time of your application wont be compromised, but requests that require content to be rendered will be slower.
You can then render your template(s) with your dynamic data, as follows
// Render the template with the supplied payload of parameters
IReadOnlyCollection<RenderedTemplate> rendered = await renderer.RenderAsync(
layoutId: "resetPassword",
payload: new { username = "Alan", returnUrl = "https://rocketmakers.com" });
Your layoutId must match a layout defined in your specified service.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
# [0.2.3](https://github.com/Rocketmakers/rocketmakers-packages/compare/templates-dotnet-v0.2.2...templates-dotnet-v0.2.3) (2026-04-01)
### Features
* **templates-dotnet:** Updated to support .NET 10 ([7936f86](https://github.com/Rocketmakers/rocketmakers-packages/commit/7936f8630176f19e516930e5f64d9cc9a34c5232))
#