Scriban is a fast, powerful and lightweight text templating language and engine for .NET
var template = Template.Parse("Hello {{name}}!")
var result = template.Render(new { name = "World" }); // => "Hello World!"
The language is very versatile, easy to read and use, similar to liquid templates:
var template = Template.Parse(@"
<ul id='products'>
{{ for product in products }}
<li>
<h2>{{ product.name }}</h2>
Price: {{ product.price }}
{{ product.description | string.truncate 15 }}
</li>
{{ end }}
</ul>
");
var result = template.Render(new { products = this.ProductList });
- Very efficient, fast parser and a lightweight runtime. CPU and Garbage Collector friendly. Check the benchmarks for more details.
- Powered by a Lexer/Parser providing a full Abstract Syntax Tree, fast, versatile and robust, more efficient than regex based parsers.
- Extensible runtime providing many extensibility points
- Precise control of whitespace text output
- Full featured language including
if
/else
/for
/while
, expressions (x = 1 + 2
), conditions... etc. - Function calls and pipes (
myvar | string.capitalize
)- Custom functions directly into the language via
func
statement and allow function pointers/delegates via thealias @ directive
- Bind .NET custom functions from the runtime API with many options for interfacing with .NET objects.
- Custom functions directly into the language via
- Complex objects (javascript/json like objects
x = {mymember: 1}
) and arrays (e.gx = [1,2,3,4]
) - Allow to pass a block of statements to a function, typically used by the
wrap
statement - Several builtins objects/functions:
- Multi-line statements without having to embrace each line by
{{...}}
- Safe language and runtime, allowing you to control what objects and functions are exposed
You can install the Scriban Extension for Visual Studio Code to get syntax coloring for scriban scripts (without HTML) and scriban html files.
- The Language for a description of the script language syntax and all the built-in functions.
- The Runtime for the a description of the runtime API and how to use it from a .NET application.
Scriban is available as a NuGet package:
Compatible with the following .NET framework profiles:
.NET3.5
.NET4.0+
via the PCL profileportable40-net40+sl5+win8+wp8+wpa81
UAP10.0+
NetStandard1.1
running onCoreCLR
Also Scriban.Signed NuGet package provides signed assemblies.
Scriban is 1.5x to x10 times faster than existing templating engines, you will find more details in our benchmarks document.
This software is released under the BSD-Clause 2 license.
- dotliquid: .NET port of the liquid templating engine by @tgjones
- Nustache: Logic-less templates for .NET
- Handlebars.Net: .NET port of handlebars.js by @rexm
Adapted logo Puzzle
by Andrew Doane from the Noun Project
Alexandre Mutel aka xoofx.