cottle icon indicating copy to clipboard operation
cottle copied to clipboard

Fast, light & extensible template engine for C#

Cottle: Compact Object to Text Transform Language

Build Status NuGet license

Overview

Cottle is an open-source (MIT) templating engine for C# .NET designed to be light (no external dependency & simple API), fast (see benchmark) and extensible (see advanced features).

Sample

Hello, {name}!

{if len(messages) > 0:
    You have {len(messages)} new message{if len(messages) > 1:s} in your mailbox!
|else:
    You have no new message.
}
var document = Document.CreateDefault(template).DocumentOrThrow;

return document.Render(Context.CreateBuiltin(new Dictionary<Value, Value>
{
    ["messages"] = GetMessages(),
    ["name"] = "JC Denton"
}));

Resource

  • Home page: https://r3c.github.io/cottle/
  • Documentation: https://cottle.readthedocs.io/
  • Benchmark: https://r3c.github.io/cottle/benchmark.html
  • NuGet package: https://www.nuget.org/packages/Cottle
  • License: license.md