PosInformatique.Foundations.Text.Templating.Scriban 1.0.0

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package PosInformatique.Foundations.Text.Templating.Scriban --version 1.0.0
                    
NuGet\Install-Package PosInformatique.Foundations.Text.Templating.Scriban -Version 1.0.0
                    
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="PosInformatique.Foundations.Text.Templating.Scriban" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PosInformatique.Foundations.Text.Templating.Scriban" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PosInformatique.Foundations.Text.Templating.Scriban" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PosInformatique.Foundations.Text.Templating.Scriban --version 1.0.0
                    
#r "nuget: PosInformatique.Foundations.Text.Templating.Scriban, 1.0.0"
                    
#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.
#:package PosInformatique.Foundations.Text.Templating.Scriban@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PosInformatique.Foundations.Text.Templating.Scriban&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PosInformatique.Foundations.Text.Templating.Scriban&version=1.0.0
                    
Install as a Cake Tool

PosInformatique.Foundations.Text.Templating.Scriban

NuGet version NuGet downloads

Introduction

This package provides a simple way to generate text using Scriban templates.

You define a Scriban template string with mustache-style syntax ({{ }}) and the library renders it to a TextWriter by using a ScribanTextTemplate<TModel> implementation. The model properties are automatically exposed to the template.

Install

You can install the package from NuGet:

dotnet add package PosInformatique.Foundations.Text.Templating.Scriban

Features

  • Render text from Scriban templates using mustache-style syntax
  • Strongly-typed model with automatic property exposure
  • Supports both POCO objects and ExpandoObject
  • Simple integration with ITextTemplateRenderContext
  • Lightweight and fast text generation

Basic usage

1. Create a model

Define a model class with the data you want to render:

public class EmailModel
{
    public string Name { get; set; }
    public string Email { get; set; }
    public DateTime Date { get; set; }
}

2. Create a Scriban template

Define a Scriban template string using mustache-style syntax:

var templateContent = @"
Hello {{ Name }},

Your email address is: {{ Email }}
Today is: {{ Date }}

Thank you!
";

3. Use ScribanTextTemplate<TModel>.RenderAsync()

Create a ScribanTextTemplate<TModel> instance and call RenderAsync():

using System.IO;
using System.Threading;
using System.Threading.Tasks;
using PosInformatique.Foundations.Text.Templating;
using PosInformatique.Foundations.Text.Templating.Scriban;

// Example of a simple ITextTemplateRenderContext implementation
public class TextTemplateRenderContext : ITextTemplateRenderContext
{
    public TextTemplateRenderContext(IServiceProvider serviceProvider)
    {
        this.ServiceProvider = serviceProvider;
    }

    public IServiceProvider ServiceProvider { get; }
}

public static class ScribanTemplateSample
{
    public static async Task GenerateAsync()
    {
        var templateContent = @"
Hello {{ Name }},

Your email address is: {{ Email }}
Today is: {{ Date }}

Thank you!
";

        // Create the Scriban text template
        var template = new ScribanTextTemplate<EmailModel>(templateContent);

        // Create a model
        var model = new EmailModel
        {
            Name = "John Doe",
            Email = "john.doe@example.com",
            Date = DateTime.UtcNow
        };

        // Build the context (can use an empty IServiceProvider if not needed)
        var context = new TextTemplateRenderContext(serviceProvider: null);

        using var writer = new StringWriter();

        // Render the template
        await template.RenderAsync(model, writer, context, CancellationToken.None);

        var result = writer.ToString();
        Console.WriteLine(result);
    }
}

Output:

Hello John Doe,

Your email address is: john.doe@example.com
Today is: 2025-01-16 10:30:00

Thank you!

4. Using ExpandoObject

You can also use ExpandoObject for dynamic models:

dynamic model = new ExpandoObject();
model.Name = "Alice";
model.Email = "alice@example.com";
model.Date = DateTime.UtcNow;

var templateContent = "Hello {{ Name }}, your email is {{ Email }}.";
var template = new ScribanTextTemplate<ExpandoObject>(templateContent);

using var writer = new StringWriter();
await template.RenderAsync(model, writer, context, CancellationToken.None);

Console.WriteLine(writer.ToString());
// Output: Hello Alice, your email is alice@example.com.

Scriban syntax

Scriban supports a rich template syntax. Here are some common examples:

Variables

Hello {{ Name }}!

Conditionals

{{ if IsActive }}
User is active
{{ else }}
User is inactive
{{ end }}

Loops

{{ for item in Items }}
- {{ item.Name }}
{{ end }}

Filters

{{ Name | upcase }}
{{ Date | date.to_string '%Y-%m-%d' }}

For more details, see the Scriban documentation.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0-rc.2 54 1/26/2026
1.1.0-rc.1 51 1/23/2026
1.0.0 425 11/19/2025
1.0.0-rc.4 363 11/19/2025
1.0.0-rc.3 379 11/18/2025
1.0.0-rc.2 374 11/18/2025
1.0.0-rc.1 371 11/18/2025

1.0.0
 - Initial release with the Scriban Text Templating feature.