Hyperbee.Templating
1.0.1
See the version list below for details.
dotnet add package Hyperbee.Templating --version 1.0.1
NuGet\Install-Package Hyperbee.Templating -Version 1.0.1
<PackageReference Include="Hyperbee.Templating" Version="1.0.1" />
<PackageVersion Include="Hyperbee.Templating" Version="1.0.1" />
<PackageReference Include="Hyperbee.Templating" />
paket add Hyperbee.Templating --version 1.0.1
#r "nuget: Hyperbee.Templating, 1.0.1"
#:package Hyperbee.Templating@1.0.1
#addin nuget:?package=Hyperbee.Templating&version=1.0.1
#tool nuget:?package=Hyperbee.Templating&version=1.0.1
Hyperbee.Templating
A simple templating engine supporting value replacements, code expressions, token nesting,
in-line definitions, and if
else
conditions.
Syntax
The templating engine supports a simple syntax.
Token Values
Token values are either simple substitutions or expression results:
{{token}}
{{context => context.token}}
{{context => context.token.ToUpper()}}
Token Conditions
Token conditions are either simple truthy tokens or expression results:
{{if token}} _truthy_content_ {{/if}}
{{if !token}} _falsy_content_ {{/if}}
{{if token}} _true_content_ {{else}} _false_content_ {{/if}}
{{if context => context.token == "test"}} _true_content_ {{/if}}
{{if context => context.token == "test"}} _true_content_ {{else}} _false_content_ {{/if}}
Methods
The templating engine supports two kinds of method evaluations; strongly typed CLR class methods through the Roslyn compiler, and dynamic methods in the form of Func expressions that are runtime bound to the expression argument context.
\\ example of CLR String.ToUpper
var parser = new TemplateParser
{
Tokens =
{
["name"] = "me"
}
};
var result = parser.Render( $"hello {{x => x.name.ToUpper()}}." );
\\ example of a Func expression MyUpper
var parser = new TemplateParser
{
Methods =
{
["MyUpper"] = args => ((string)args[0]).ToUpper()
},
Tokens =
{
["name"] = "me"
}
};
var result = parser.Render( $"hello {{x => x.MyUpper( x.name )}}." );
Token Nesting
Token values can contain tokens.
\\ example of token nesting
var parser = new TemplateParser
{
Tokens =
{
["fullname"] = "{{first}} {{last}}",
["first"] = "Hari",
["last"] = "Seldon"
}
};
var result = parser.Render( $"hello {{fullname}}." );
Inline Token Definitions
You can define tokens, inline, within a template. Inline tokens must be defined before they are referenced.
{{identity:"me"}}
hello {{identity}}.
{{identity:{{x=> "me"}} }}
hello {{identity}}.
TODO
It would be useful to support simple enumerations.
{{each regex}}
{{@value}} {{@index}}
{{/each}}
{{each x => IEnumeration<string>}}
{{ x => x().value + x().index }}
{{/each}}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Hyperbee.Resources (>= 1.0.0)
- Microsoft.CodeAnalysis.CSharp.Scripting (>= 4.9.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Hyperbee.Templating:
Package | Downloads |
---|---|
Hyperbee.Templating.Provider.XS
Adds an ITokenExpressionProvider powder by Hyperbee.XS |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.2.0 | 102 | 5/9/2025 |
3.1.0 | 144 | 5/1/2025 |
3.0.2 | 191 | 4/14/2025 |
3.0.2-develop.250414130051 | 164 | 4/14/2025 |
3.0.1 | 126 | 2/17/2025 |
3.0.1-develop.250217125033 | 74 | 2/17/2025 |
3.0.0 | 111 | 12/19/2024 |
3.0.0-develop.241219164731 | 66 | 12/19/2024 |
2.0.0 | 194 | 8/23/2024 |
1.0.3 | 151 | 8/13/2024 |
1.0.2 | 139 | 8/13/2024 |
1.0.1 | 155 | 4/11/2024 |
1.0.0 | 146 | 4/9/2024 |