Open source, MIT licensed

Liquid templates for .NET. Fast, safe, yours.

Fluid parses and renders Liquid, the template language of Shopify, with few allocations. Templates only read the data you allow, so your users can write them, and every filter, tag and operator can be extended.

dotnet add package Fluid.Core

products.liquid

<ul>
{% for product in products %}
  <li>{{ product.name | upcase }}
    {{ product.price | money }}
  </li>
{% endfor %}
</ul>

Output

<ul>
  <li>APPLE $329.00</li>
  <li>ORANGE $25.00</li>
  <li>BANANA $99.00</li>
</ul>

Features

Everything Liquid, and what .NET applications need

  1. 01

    Shopify compatible

    Reads templates like Shopify Liquid, verified with the Golden Liquid test suite and against Shopify's own engine.

    Liquid syntax
  2. 02

    Fast, few allocations

    A hand-written parser, no regular expressions, and a synchronous fast path for async rendering.

    Benchmarks
  3. 03

    Secure by design

    Templates read an allow-listed model, and limits bound recursion, steps, output size and collections.

    Security
  4. 04

    Async everything

    Filters, member accessors and file providers can be asynchronous, and renderings can be cancelled.

    Parsing and rendering
  5. 05

    Your own grammar

    Register tags, blocks, operators and functions, with any parser built from Parlot combinators.

    Extending the grammar
  6. 06

    Any .NET model

    POCOs, dictionaries, JsonNode and custom values, with value converters and naming policies.

    Models and values
  7. 07

    Source generators

    Read models without reflection for NativeAOT, or compile .liquid files into C# at build time.

    Compiled templates
  8. 08

    ASP.NET Core views

    Liquid views with layouts, sections and _ViewStart files, for MVC or Minimal APIs.

    View engines

Three lines

Parse once, render many times

A parser and the options are created once and shared by the whole application. Parsed templates are thread-safe and can be cached, and each rendering gets its own context.

Getting started
var parser = new FluidParser();

var template = parser.Parse("Hello {{ name | capitalize }}!");

var context = new TemplateContext(new { name = "world" });

Console.WriteLine(await template.RenderAsync(context));
// Hello World!

Benchmarks

Faster than the other .NET Liquid engines

Rendering a page of 100 products with filters and properties, with BenchmarkDotNet.

Render benchmark: Fluid takes less time and allocates less memory than Handlebars.Net, Scriban and DotLiquid All results

Write a template now.

The playground runs Fluid in your browser with WebAssembly. Change the template, the model and the options, and share a link to the result.

Open the playground

Esc to close