Scriban is a fast, powerful, safe and lightweight text templating language and engine for .NET, 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 });
NOTICE
By default, Properties and methods of .NET objects are automatically exposed with lowercase and
_
names. It means that a property likeMyMethodIsNice
will be exposed asmy_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 aMemberRenamer
delegate
Template.ToText
, allowing to manipulate scripts in memory and re-save them to the disk, useful for roundtrip script update scenarios
liquid
by using the Template.ParseLiquid
method
liquid
language is less powerful than scriban, this mode allows to migrate from liquid
to scriban
language easilyliquid
script to a scriban script using Template.ToText
on a template parsed with Template.ParseLiquid
async
/await
evaluation of scripts (e.g Template.RenderAsync
)if
/else
/for
/while
, expressions (x = 1 + 2
), conditions... etc.myvar | string.capitalize
)
func
statement and allow function pointers/delegates via the alias @ directive
x = {mymember: 1}
) and arrays (e.g x = [1,2,3,4]
)wrap
statement{{...}}
You can install the Scriban Extension for Visual Studio Code to get syntax coloring for scriban scripts (without HTML) and scriban html files.
Scriban is available as a NuGet package:
Compatible with the following .NET framework profiles:
Also the Scriban.Signed NuGet package provides signed assemblies.
Scriban is blazing fast! For more details, you can check the benchmarks document.
This software is released under the BSD-Clause 2 license.
Adapted logo Puzzle
by Andrew Doane from the Noun Project
Alexandre Mutel aka xoofx.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。