VOOZH about

URL: https://www.nuget.org/packages/Simplify.Templates/

⇱ NuGet Gallery | Simplify.Templates 2.0.3




👁 Image
Simplify.Templates 2.0.3

dotnet add package Simplify.Templates --version 2.0.3
 
 
NuGet\Install-Package Simplify.Templates -Version 2.0.3
 
 
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="Simplify.Templates" Version="2.0.3" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Simplify.Templates" Version="2.0.3" />
 
Directory.Packages.props
<PackageReference Include="Simplify.Templates" />
 
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 Simplify.Templates --version 2.0.3
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Simplify.Templates, 2.0.3"
 
 
#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 Simplify.Templates@2.0.3
 
 
#: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=Simplify.Templates&version=2.0.3
 
Install as a Cake Addin
#tool nuget:?package=Simplify.Templates&version=2.0.3
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Simplify.Templates Documentation

Provides ITemplate interface, Template class, and TemplateBuilder class for working with text templates.

With Simplify.Templates, you can easily load text templates, localize them, insert data, and get the generated result.

Available at NuGet as binary package

Quick Start

Load the template from a file located in the current assembly directory:

var tpl = TemplateBuilder
 .FromLocalFile("TestTemplate.tpl")
 .Build();

The TestTemplate.tpl file:

<html>
<body>
<div>{SomeVariable}</div>
<div>{Items}</div>
</body>

Setting data into the template variables:

tpl.Set("SomeVariable", "footext");

tpl.Add("Items", "1")
 .Add("Items", "2")
 .Add("Items", "3");

Getting the template text:

var str = tpl.Get();

str will contain:

<html>
<body>
<div>footext</div>
<div>123</div>
</body>

Other Ways of Template Loading

To choose how to load a template, use respective TemplateBuilder static methods:

  • Loading template from a string: FromString("some string")
  • Loading template from a file: FromFile("D:\SomeDir\SomeFile.txt")
  • Loading template from a file located in the current assembly directory: FromLocalFile("SomeFile.txt")
  • Loading template from current assembly embedded resources: FromCurrentAssembly("FilePath.Filename.tpl") or FromCurrentAssembly("FilePath/Filename.tpl")
  • Loading template from specified assembly embedded resources: FromAssembly("FilePath.Filename.tpl", myAssembly)

Template Localization

If you want a template to be localizable, create an XML file in the same directory as the template file.

Files should be named like FooTemplate.tpl.en.xml if the template file name is FooTemplate.tpl. For embedded templates, it should be named like FooTemplate.tpl-en.xml.

You can keep several files for each language you want to localize, for example:

FooTemplate.tpl
FooTemplate.tpl.en.xml
FooTemplate.tpl.de.xml
FooTemplate.tpl.ru.xml

Localization file FooTemplate.tpl.de.xml example:

<?xml version="1.0" encoding="utf-8"?>
<items>
 <item name="LocalizableVariable" value="Test" />
</items>

Localization file FooTemplate.tpl.en.xml example:

<?xml version="1.0" encoding="utf-8"?>
<items>
 <item name="LocalizableVariable" value="Test default" />
 <item name="LocalizableVariable2">
 <a href="#">localizable data default</a>
 </item>
</items>

Template file FooTemplate.tpl example:

<html>
<body>
<div>{LocalizableVariable}</div>
<div>{LocalizableVariable2}</div>
</body>

To perform localization, use respective fluent methods: Localizable, LocalizableFromCurrentThreadLanguage.

There are two language code parameters: the current language and the default language.

At the time the template builds, the current language localization file will be inserted into the template, followed by the default localization file. If some localizable values do not exist in the current localization file, they will be inserted from the default localization file.

To use Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName as the current language code, use the LocalizableFromCurrentThreadLanguage method.

Output example:

var tpl = TemplateBuilder
 .FromLocalFile("FooTemplate.tpl")
 .Localizable("de", "en")
 .Build();

var str = tpl.Get();

str will contain:

<html>
<body>
<div>Test</div>
<div><a href="#">localizable data default</a></div>
</body>

Building Items List Example

The MasterTemplate.tpl file:

<html>
<body>
{Links}
</body>

The FooLinkItem.tpl file:

<a href="http://foolink/{ItemID}">{MyLinkLabel} {ItemID}</a><br />

The FooLinkItem.tpl.en.xml file:

<?xml version="1.0" encoding="utf-8"?>
<items>
 <item name="MyLinkLabel" value="My item" />
</items>

Building links list:

class MyItem
{
 public int ID { get; set; }
}

...

var items = new List<MyItem> { new MyItem {ID = 1}, new MyItem {ID = 2}, new MyItem {ID = 3} };

var tpl = TemplateBuilder
 .FromFile("Templates/MasterTemplate.tpl")
 .Build();

var itemTpl = TemplateBuilder
 .FromFile("Templates/FooLinkItem.tpl")
 .Build();

foreach (var item in items)
{
 itemTpl.Set("ItemID", item.ID);

 // Adding our generated item data to the master template and rolling it back to initial, but localized state
 tpl.Add("Links", itemTpl.GetAndRoll());
}

var str = tpl.Get();

str will contain:

<html>
<body>
<a href="http://foolink/1">My item 1</a><br />
<a href="http://foolink/2">My item 2</a><br />
<a href="http://foolink/3">My item 3</a><br />
</body>

Model Binding Example

The MyTemplate.tpl file:

{Prop1}
{Prop2}
{Prop3}

The model:

public class MyClass
{
 public string Prop1 { get; set; }
 public int Prop2 { get; set; }
 public DateTime Prop3 { get; set; }
}

Setting model to template:

var obj = new MyClass {Prop1 = "Foo", Prop2 = 5, Prop3 = new DateTime(2014, 09, 13)};

var tpl = TemplateBuilder
 .FromFile("MyTemplate.tpl")
 .Build();

tpl.Model(obj).With(x => x.Prop3, x => x.ToString("dd.MM.yyyy")).Set();

var str = tpl.Get();

str will contain:

Foo
5
13.09.2014
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 is compatible.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Simplify.Templates:

Package Downloads
Simplify.Web

Lightweight and fast .NET web-framework based on MVC and OWIN

AcspNet

ACSP.NET is a lightweight and fast .NET web-framework based on MVC and OWIN.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.3 166 6/25/2026
2.0.2 3,699 5/25/2024
2.0.1 3,282 8/8/2023
2.0.0 22,675 12/8/2019
2.0.0-pre01 684 12/7/2019
1.5.2 3,477 9/28/2019
1.5.1 2,612 6/23/2019
1.5.0 2,255 12/16/2018
1.5.0-pre01 889 11/21/2018
1.4.1 1,501 10/1/2018
1.4.0 1,902 4/12/2018
1.3.0 2,755 8/18/2017
1.2.1 6,272 8/18/2016
1.2.0 2,712 6/1/2015
1.1.2 7,952 10/23/2014
1.1.1 2,565 9/21/2014
1.1.0 3,646 9/2/2014
1.0.5 2,419 8/8/2014
Loading failed