Kkts.Template
2.0.2
dotnet add package Kkts.Template --version 2.0.2
NuGet\Install-Package Kkts.Template -Version 2.0.2
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="Kkts.Template" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kkts.Template --version 2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Kkts.Template, 2.0.2"
#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.
// Install Kkts.Template as a Cake Addin #addin nuget:?package=Kkts.Template&version=2.0.2 // Install Kkts.Template as a Cake Tool #tool nuget:?package=Kkts.Template&version=2.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Kkts.Template
Kkts.Template is a .Net template engine for resolving simple template like SMS, emails, or any other formatted text output.
No regular expressions
get via nuget Kkts.Expressions
Usage
class TagResolver : ITagResolver
{
public Task<object> ResolveAsync(string tagName, CultureInfo cultureInfo)
{
switch (tagName.ToLower())
{
case "title":
return Task.FromResult<object>("Kk.Template");
case "des":
return Task.FromResult<object>("this is light-weight template engine");
case "label":
return Task.FromResult<object>("City");
case "contries":
return Task.FromResult<object>(new[] { "Vietnam", "Japan" });
case "cities":
return Task.FromResult<object>(new[] { new Data { Id = 1, Name = "HCM" }, new Data { Id = 2, Name = "Hanoi" } });
default:
return Task.FromResult<object>(string.Empty);
}
}
}
var tmpl = TemplateEngine.Parse("<h1>{title}</h1><p>{des}</p>");
var engine = new TemplateEngine(new TagResolver());
var result = await engine.ResolveAsync(tmpl);
// "<h1>Kk.Template</h1><p>this is light-weight template engine</p>"
Description | Template | Resolved | Note |
---|---|---|---|
Tag name | <h1>{title}</h1> | <h1>Kk.Template</h1> | title is a tag that is resolved as 'Kk.Template' |
Escape curly brackets | <h1>{{title}</h1> | <h1>{title}</h1> | title is not a tag, "{{" is resolved as '{' |
Escape curly brackets | <h1>{{title}}</h1> | <h1>{title}}</h1> | title is not a tag, "{{" is resolved as '{' and all the '}' are kept as they are |
Loop | {(contries)<li>{item}</li>} | <li>Vietnam</li><li>Japan</li> | contries is an Enumerable<string> |
Loop | {(cities)<li>{order} - {label}: {item.Name}</li>} | <li>1 - City: HCM</li><li>2 - City: Hanoi</li> | cities is an Enumerable<Data>, label is a tag, item is an element of cities |
Note:
Some keywords in loop context
1 - index (count from 0, 1, ..., n)
2 - order (count from 1, 2, ..., n)
3 - item (element of collection)
Contacts
LinkedIn Skype: linh.nhat.le
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.