Scriban 5.4.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Scriban --version 5.4.1
NuGet\Install-Package Scriban -Version 5.4.1
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="Scriban" Version="5.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Scriban --version 5.4.1
#r "nuget: Scriban, 5.4.1"
#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.
// Install Scriban as a Cake Addin
#addin nuget:?package=Scriban&version=5.4.1

// Install Scriban as a Cake Tool
#tool nuget:?package=Scriban&version=5.4.1

scriban Build Status Coverage Status NuGet

<img align="right" width="160px" height="160px" src="img/scriban.png">

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.

// 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.

NOTICE

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

New in 3.0+

  • AST is now fully visitable with ScriptVisitor. You can now access Parent on any ScriptNode object and navigate the AST.
    • Improve AST round-trip by preserving whitespaces around template enter{{ and exit}}
  • Several new language features:
    • Hexadecimal/binary numbers: 0x1ef or 0b101010
    • Support for large integers
    • New parametric functions: func sub(x,y = 1, z...); ret x - y - z[0]; end
    • New inline functions: sub(x,y) = x - y
    • Optional member access with ?. instead of regular . (e.g a?.b?.c)
    • Conditional expressions: cond ? a : b
  • Separate language mode (via ScriptLang enum) from template/scripting parsing mode (ScriptMode).
  • New language parsing mode Scientific, in addition to default Scriban and Liquid language mode.
  • More fine-grained options on the TemplateContext to define scripting behaviors (EnableRelaxedTargetAccess, EnableRelaxedMemberAccess, EnableRelaxedFunctionAccess, EnableRelaxedIndexerAccess, EnableNullIndexer)
  • New object.eval and object.eval_template function to evaluate Scriban expressions/templates at runtime.
  • Better support for IFormattable objects.

Features

  • 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.
    • Precise source code location (path, column and line) for error reporting
    • Write an AST to a script textual representation, with Template.ToText, allowing to manipulate scripts in memory and re-save them to the disk, useful for roundtrip script update scenarios
  • Compatible with liquid by using the Template.ParseLiquid method
    • While the liquid language is less powerful than scriban, this mode allows to migrate from liquid to scriban language easily
    • With the AST to text mode, you can convert a liquid script to a scriban script using Template.ToText on a template parsed with Template.ParseLiquid
    • As the liquid language is not strictly defined and there are in fact various versions of liquid syntax, there are restrictions while using liquid templates with scriban, see the document liquid support in scriban for more details.
  • Extensible runtime providing many extensibility points
  • Support for async/await evaluation of scripts (e.g Template.RenderAsync)
  • 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)
  • Complex objects (javascript/json like objects x = {mymember: 1}) and arrays (e.g x = [1,2,3,4])
  • Allow to pass a block of statements to a function, typically used by the wrap statement
  • Several built-in functions:
  • Multi-line statements without having to embrace each line by {{...}}
  • Safe parser and safe runtime, allowing you to control what objects and functions are exposed

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

Binaries

Scriban is available as a NuGet package: NuGet

Compatible with the following .NET Standard 2.0+ (New in 3.0)

For support for older framework (.NET 3.5, 4.0, 4.5, .NET Standard 1.1, 1.3, they are only provided in older Scriban 2.x, which is no longer supported.

Also the Scriban.Signed NuGet package provides signed assemblies.

Source Embedding

Starting with Scriban 3.2.1+, the package comes with source included so that you can internalize your usage of Scriban into your project. This can be useful in an environment where you can't easily consume NuGet references (e.g Roslyn Source Generators).

WARNING: Currently, the Scriban sources are not set as readonly, so you should not modify Scriban sources in that mode as it will modify the sources for other projects using Scriban on your machine. Use this feature at your own risks!

In order to activate this feature you need to:

  • Set the property PackageScribanIncludeSource to true in your project:
    <PropertyGroup>
      <PackageScribanIncludeSource>true</PackageScribanIncludeSource>
    </PropertyGroup>
    
  • Add the IncludeAssets="Build" to the NuGet PackageReference for Scriban:
    <ItemGroup>
      <PackageReference Include="Scriban" Version="3.2.1" IncludeAssets="Build"/>
    </ItemGroup>
    

If you are targeting netstandard2.0 or .NET Framework 4.7.2+, in order to compile Scriban you will need these NuGet package references (that can come from a dependency that you already have):

<ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
    <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.0" />
</ItemGroup>

NOTE: In this mode, all Scriban types are marked as internal.

You should see a Scriban folder and empty subfolders in your project. This is an issue with Visual Studio 2019 16.8.x (and before) and it will be fixed in VS 2019 16.9+

Benchmarks

Scriban is blazing fast! For more details, you can check the benchmarks document.

License

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

  • dotliquid: .NET port of the liquid templating engine
  • Fluid .NET liquid templating engine
  • Nustache: Logic-less templates for .NET
  • Handlebars.Net: .NET port of handlebars.js
  • Textrude: UI and CLI tools to turn CSV/JSON/YAML models into code using Scriban templates
  • NTypewriter: VS extension to turn C# code into documentation/TypeScript/anything using Scriban templates

Online Demo

Credits

Adapted logo Puzzle by Andrew Doane from the Noun Project

Author

Alexandre Mutel aka xoofx.

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

NuGet packages (137)

Showing the top 5 NuGet packages that depend on Scriban:

Package Downloads
Volo.Abp.TextTemplating.Scriban The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Package Description

Serenity.CodeGenerator The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Generates server and script side code for Serenity platform applications

Miru.Core

Package Description

Mediator.SourceGenerator

A high performance .NET Mediator pattern implemenation using source generation.

RecommendationsGatewayModule.Data

Package Description

GitHub repositories (35)

Showing the top 5 popular GitHub repositories that depend on Scriban:

Repository Stars
abpframework/abp
Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
dodyg/practical-aspnetcore
Practical samples of ASP.NET Core 8.0, 7.0, 6.0, 5.0, 3.1, 2.2, and 2.1,projects you can use. Readme contains explanations on all projects.
spectreconsole/spectre.console
A .NET library that makes it easier to create beautiful console applications.
openiddict/openiddict-core
Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
TelegramBots/Telegram.Bot
.NET Client for Telegram Bot API
Version Downloads Last updated
5.9.1 178,932 1/9/2024
5.9.0 516,441 9/6/2023
5.8.0 7,238 9/1/2023
5.7.0 1,010,699 2/25/2023
5.6.0 98,806 2/3/2023
5.5.2 235,823 1/4/2023
5.5.1 220,646 11/18/2022
5.5.0 1,072,721 7/11/2022
5.4.6 443,705 5/29/2022
5.4.5 27,554 5/22/2022
5.4.4 1,788,816 4/9/2022
5.4.3 52,521 4/3/2022
5.4.2 9,116 3/31/2022
5.4.1 83,381 3/15/2022
5.4.0 165,783 2/6/2022
5.3.0 2,142 2/6/2022
5.2.0 7,398 2/6/2022
5.1.0 1,917 2/5/2022
5.0.0 764,866 10/20/2021
4.1.0 35,313 10/7/2021
4.0.2 642,508 9/22/2021
4.0.1 796,390 6/3/2021
4.0.0 3,781 6/2/2021
3.9.0 21,963 5/31/2021
3.8.2 24,909 5/27/2021
3.8.1 59,135 5/25/2021
3.8.0 1,696 5/25/2021
3.7.0 117,735 5/1/2021
3.6.0 986,196 3/20/2021
3.5.0 228,862 2/13/2021
3.4.2 41,471 2/1/2021
3.4.1 39,274 1/23/2021
3.4.0 14,441 1/21/2021
3.3.3 70,831 1/14/2021
3.3.2 125,077 12/30/2020
3.3.1 51,129 12/30/2020
3.3.0 2,095 12/29/2020
3.2.2 3,909 12/24/2020
3.2.1 16,424 12/22/2020
3.2.0 1,788 12/22/2020
3.1.0 6,686 12/21/2020
3.0.7 27,093 12/15/2020
3.0.6 119,653 12/6/2020
3.0.5 241,959 12/1/2020
3.0.4 5,112 11/30/2020
3.0.3 3,403 11/29/2020
3.0.2 70,778 11/23/2020
3.0.1 1,991 11/22/2020
3.0.0 17,730 11/15/2020
3.0.0-alpha.9 4,932 8/20/2020
3.0.0-alpha.8 433 8/7/2020
3.0.0-alpha.7 282 7/31/2020
3.0.0-alpha.6 296 7/31/2020
3.0.0-alpha.5 577 7/25/2020
3.0.0-alpha.4 350 7/25/2020
3.0.0-alpha.3 10,832 7/16/2020
3.0.0-alpha.2 326 7/6/2020
3.0.0-alpha.1 409 6/18/2020
2.1.4 483,216 8/16/2020
2.1.3 883,867 6/5/2020
2.1.2 326,886 3/8/2020
2.1.1 359,749 12/6/2019
2.1.0 311,692 6/30/2019
2.0.1 527,559 5/11/2019
2.0.0 171,725 3/8/2019
2.0.0-alpha-006 545 3/7/2019
2.0.0-alpha-005 3,387 1/15/2019
2.0.0-alpha-004 1,338 1/4/2019
2.0.0-alpha-003 578 1/3/2019
2.0.0-alpha-002 666 1/1/2019
2.0.0-alpha-001 596 12/28/2018
1.2.9 111,500 12/21/2018
1.2.8 6,729 12/17/2018
1.2.7 192,151 10/6/2018
1.2.6 8,576 9/26/2018
1.2.5 9,856 8/29/2018
1.2.4 3,340 8/21/2018
1.2.3 106,122 7/20/2018
1.2.2 7,170 7/3/2018
1.2.1 27,036 6/1/2018
1.2.0 26,704 2/10/2018
1.1.1 5,689 1/22/2018
1.1.0 1,078 1/22/2018
1.0.0 122,771 12/24/2017
1.0.0-beta-006 976 12/12/2017
1.0.0-beta-005 801 12/3/2017
1.0.0-beta-004 1,082 11/19/2017
1.0.0-beta-003 1,036 11/19/2017
1.0.0-beta-002 1,011 11/13/2017
1.0.0-beta-001 998 11/12/2017
0.16.0 13,471 11/12/2017
0.15.0 10,364 11/9/2017
0.14.0 1,256 11/7/2017
0.13.0 1,254 11/7/2017
0.12.1 1,264 11/6/2017
0.12.0 1,244 11/6/2017
0.11.0 1,262 11/4/2017
0.10.0 1,219 11/1/2017
0.9.1 1,227 10/27/2017
0.9.0 1,216 10/25/2017
0.9.0-pre100 1,049 10/23/2017
0.7.0 27,304 10/12/2017
0.6.0 1,581 5/16/2017
0.5.0 1,057 5/16/2017
0.4.0 1,057 5/8/2017
0.3.1 1,068 4/4/2017
0.3.1-pre028 846 4/4/2017
0.3.0 1,071 3/9/2017
0.2.2 1,113 2/2/2017
0.2.1 1,141 2/1/2017
0.2.0 1,826 6/27/2016
0.1.0 3,962 5/31/2016