Skip to content

Integration

Craig edited this page Oct 17, 2017 · 2 revisions

Integrating with Nettle is simple. Nettle doesn't have any dependencies, so you just need to install a single NuGet package:

Install-Package Nettle

To use Nettle we need to create a compiler and compile a template. Templates are returned as a Func<object, string> delegate where the object is the templates model and the return value is the content that gets generated. The following code will create a Nettle compiler and compile a simple template:

var source = @"Welcome {{Name}}";

var model = new
{
    Name = "John Smith"
};

var compiler = NettleEngine.GetCompiler();
var template = compiler.Compile(source);
var output = template(model);

/* Result:
Welcome John Smith
*/

Extensions

Nettle has various extensions such as Nettle.Data and Nettle.Web. See extensions for more information.

Clone this wiki locally