HTML templates and mail merge

    Build reusable HTML email and document templates inside your Avalonia application. Insert fields such as customer names or reference numbers from your own commands, then merge your application values and export the completed HTML.

    An Avalonia HTML Editor mail-merge template containing a registered CustomerName placeholder.
    An Avalonia HTML Editor mail-merge template containing a registered CustomerName placeholder.
    The completed Avalonia HTML Editor mail-merge document showing the resolved customer name.
    The completed Avalonia HTML Editor mail-merge document showing the resolved customer name.
    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.

    Use a template in your application

    1. Create the formatted template and insert the fields your application provides.
    2. Save the unmerged template so it can be reused for another message or document.
    3. Load a copy, merge values using exact field display names, then export the finished HTML.

    The insertion token and field display name are separate values. Merge values are literal text, including Unicode and markup characters. When preparing an email with images, use the email export workflow before handing the message to your delivery service.

    Related guides

    Last updated on Oct 30, 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.