Mail-merge placeholders

    Define the fields your application can resolve, let users insert them in a template, then merge values when preparing the finished document.

    Actual public Avalonia sample with a customer-name placeholder in the greeting and its exported template markup below.
    Actual public Avalonia sample with a customer-name placeholder in the greeting and its exported template markup below.
    The same actual Avalonia sample after merging a literal Unicode value, with escaped angle brackets visible in the exported HTML.
    The same actual Avalonia sample after merging a literal Unicode value, with escaped angle brackets visible in the exported HTML.
    using SpiceLogic.HtmlEditor.Abstractions.Entities.MailMerge;
    
    var name = new PlaceholderField("Customer name", "{{CustomerName}}");
    editor.MailMerge.PlaceholderFields.Add(name);
    await editor.MailMerge.InsertPlaceholderAsync(name);
    await editor.MailMerge.MergeAsync(new Dictionary<string, string?>
    {
        ["Customer name"] = "Alex & Morgan"
    });
    string html = await editor.GetBodyHtmlAsync();

    Merge keys are exact display names stored in the field's data-sl-field attribute. Values become literal text, including markup characters. Unsupplied fields remain in the template. Use GetFieldsAsync to discover the fields in accepted content.

    Keep values literal

    Merge values are text, including angle brackets, ampersands and Unicode. The field display name is the lookup key; its insertion token is separate template data. A field without a supplied value remains available for a later merge.

    Last updated on Oct 18, 2026

    Put this into practice.

    Start with the C# Avalonia sample. Restore this edition's package and install the native browser prerequisites before running it.

    Prefer a guided look? Book a free live demo with our engineers - live on Zoom or Teams, never a chatbot.