Handlebars.Net.Helpers

June 10, 2025 ยท View on GitHub

Several helpers which can be used for Handlebars.Net

Project

Build AzureBuild Status Azure
Sonar QualitySonar Quality Gate Sonar Bugs Sonar Code Smells
CoverageSonar Coverage codecov

Packages

PackageNugetMyGet :information_source:
Handlebars.Net.HelpersNuGetMyGet
Handlebars.Net.Helpers.DynamicLinqNuGetMyGet
Handlebars.Net.Helpers.HumanizerNuGetMyGet
Handlebars.Net.Helpers.JsonNuGetMyGet
Handlebars.Net.Helpers.RandomNuGetMyGet
Handlebars.Net.Helpers.XegerNuGetMyGet
Handlebars.Net.Helpers.XPathNuGetMyGet
Handlebars.Net.Helpers.XsltNuGetMyGet

Framework support

  • .NET Framework 4.5.1 4.5.2 and 4.6
  • .NET Standard 1.3, 2.0 and 2.1
  • .NET 6.0 and .NET 8.0

:exclamation: Breaking changes

2.5.0

Some breaking changes are introduced in this version:

A. EnvironmentHelpers

By default, the category Environment is not automatically registered due to potential security issues. You need to allow this via the HandlebarsHelpersOptions.

B. System.Linq.Dynamic.Core

By default, the category DynamicLinq is not automatically registered due to a CVE in System.Linq.Dynamic.Core DynamicLinq. This means that the NuGet Handlebars.Net.Helpers.DynamicLinq will not be loaded and registered automatically anymore. You need to allow this via the HandlebarsHelpersOptions. In addition, an extra configuration setting is added to allow the use of ToString and Equals on an object.

Example:

var handlebarsContext = HandlebarsDotNet.Handlebars.Create();
HandlebarsHelpers.Register(handlebarsContext, o =>
{
    o.DynamicLinqHelperOptions = new HandlebarsDynamicLinqHelperOptions
    {
        AllowEqualsAndToStringMethodsOnObject = true
    };
});

Usage

Register

Get all helpers

var handlebarsContext = HandlebarsDotNet.Handlebars.Create();
HandlebarsHelpers.Register(handlebarsContext);

Get a specific helper

var handlebarsContext = HandlebarsDotNet.Handlebars.Create();
HandlebarsHelpers.Register(handlebarsContext, Category.String);

Get multiple helpers

var handlebarsContext = HandlebarsDotNet.Handlebars.Create();
HandlebarsHelpers.Register(handlebarsContext, Category.Math, Category.String);

Using

With a category prefix (default)

By default you can use the helpers by using a prefix from the category:

{{[String.Append] "foobar" "bar"}}

With an additional custom prefix

If you would like to use the helpers with a custom prefix, you need to register the helpers using this code:

HandlebarsHelpers.Register(handlebarsContext, options => { Prefix = "custom"; });

Now you can only access the helpers by using the custom prefix, category prefix and the name like:

{{[custom.String.Append] "foobar" "bar"}}

With a custom prefix separator character

By default the dot (.) character is used, use the code below to use a different value:

HandlebarsHelpers.Register(handlebarsContext, options => { PrefixSeparator = "-"; });

Now you can only access the helpers by using the - separator like this:

{{[String-Append] "foobar" "bar"}}

Without a prefix

If you would like to use the helpers without a prefix, so just by name, use this code:

HandlebarsHelpers.Register(handlebarsContext, options => { UseCategoryPrefix = false; });

Now you can use it like:

{{String-Append "foobar" "bar"}}

Now you can access the helpers by just using the name like:

{{Append "foobar" "bar"}}

The following default built-in helpers are available:

And the following additonal helpers are available:


References

Example