The Principal Dev – Masterclass for Tech Leads

The Principal Dev – Masterclass for Tech Leads28-29 May

Join

scriban ci Coverage Status NuGet

Scriban is a fast, powerful, safe and lightweight scripting language and engine for .NET, which was primarily developed for text templating with a compatibility mode for parsing liquid templates.

Today, not only Scriban can be used in text templating scenarios, but also can be integrated as a general scripting engine: For example, Scriban is at the core of the scripting engine for kalk, a command line calculator application for developers.

// Parse a scriban template
var template = Template.Parse("Hello {{name}}!");
var result = template.Render(new { Name = "World" }); // => "Hello World!" 

Parse a Liquid template using the Liquid language:

// Parse a liquid template
var template = Template.ParseLiquid("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 });

Scriban can also be used in pure scripting context without templating ({{ and }}) and can help you to create your own small DSL.

[!NOTE] By default, Properties and methods of .NET objects are automatically exposed with lowercase and _ names. It means that a property like MyMethodIsNice will be exposed as my_method_is_nice. This is the default convention, originally to match the behavior of liquid templates. If you want to change this behavior, you need to use a MemberRenamer delegate

Highlights

Features

Syntax Coloring

You can install the Scriban Extension for Visual Studio Code to get syntax coloring for scriban scripts (without HTML) and scriban html files.

Documentation

The full documentation is available at https://scriban.github.io.

Installation

Scriban is available as a NuGet package: NuGet

dotnet add package Scriban

The package targets netstandard2.0 and net8.0, so it works with .NET 6+, .NET Framework 4.7.2+, and other compatible runtimes.

Also the Scriban.Signed NuGet package provides signed assemblies.

Source Embedding

The package includes Scriban source files so that you can internalize Scriban into your project instead of consuming it only as a binary dependency. This is useful in environments where NuGet references are not convenient, such as Roslyn source generators.

Check the documentation here

License

This software is released under the BSD-Clause 2 license.

Online Demo

Sponsors

Supports this project with a monthly donation and help me continue improving it. [Become a sponsor]

lilith Lilith River, author of Imageflow Server, an easy on-demand image editing, optimization, and delivery server

Credits

Adapted logo Puzzle by Andrew Doane from the Noun Project

Author

Alexandre Mutel aka xoofx.

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.