HtmlEmailTemplate Class
Provides a templating engine specialized for generating HTML email content with automatic encoding and metadata extraction.
public class HtmlEmailTemplate : TemplateExample
using var template = new HtmlEmailTemplate();
template.Load("<title>{{@begin_section title}}Welcome{{@end_section}}</title><h1>Hello {{#html userName}}!</h1>");
template.Arguments.Add(new TemplateArgument("userName", typeof(string)));
var result = template.Run(out var metadata, new Dictionary<string, object?> { ["userName"] = "John" });
Assert.Equal("<title>Welcome</title><h1>Hello John!</h1>", result);
Assert.NotNull(metadata);
Assert.Equal("Welcome", metadata.Title);- Inheritance
TemplateHtmlEmailTemplate
Constructors
| Name | Description |
|---|---|
| HtmlEmailTemplate() |
HtmlEmailTemplate()
HtmlEmailTemplate.cspublic HtmlEmailTemplate()No documentation is available.
Methods
| Name | Description |
|---|---|
| CreateCodeBlock(string, int) | Creates an HTML-specific code block that supports HTML encoding, URL encoding, sections, and content identifiers. |
| CreateDirectiveBlock(string, string, string, int) | |
| CreateOutput(TextWriter) | Creates an HTML email output writer with encoding capabilities and section support. |
| InvokeRunMethod(object?[]) | Runs the template, then rejects it if it left a section open. |
| Run(HtmlEmailMetadata?) | Runs the template without parameters and returns the generated HTML along with extracted metadata. |
| Run(HtmlEmailMetadata?, IDictionary<string, object?>) | Runs the template with named parameters and returns the generated HTML along with extracted metadata. |
| Run(HtmlEmailMetadata?, object?[]) | Runs the template with positional parameters and returns the generated HTML along with extracted metadata. |
| Run(TextWriter, HtmlEmailMetadata?) | Runs the template without parameters and writes the generated HTML to the specified writer. |
| Run(TextWriter, HtmlEmailMetadata?, IReadOnlyDictionary<string, object?>) | Runs the template with named parameters and writes the generated HTML to the specified writer. |
| Run(TextWriter, HtmlEmailMetadata?, object?[]) | Runs the template with positional parameters and writes the generated HTML to the specified writer. |
CreateCodeBlock(string, int)
HtmlEmailTemplate.csCreateDirectiveBlock(string, string, string, int)
HtmlEmailTemplate.csprotected override DirectiveBlock CreateDirectiveBlock(string text, string name, string value, int index)No documentation is available.
CreateOutput(TextWriter)
HtmlEmailTemplate.csCreates an HTML email output writer with encoding capabilities and section support.
protected override object CreateOutput(TextWriter writer)InvokeRunMethod(object?[])
HtmlEmailTemplate.csRuns the template, then rejects it if it left a section open.
Run overloads
Run(HtmlEmailMetadata?)
HtmlEmailTemplate.csRuns the template without parameters and returns the generated HTML along with extracted metadata.
public virtual string Run(out HtmlEmailMetadata? metadata)Parameters
metadataHtmlEmailMetadata?- Receives metadata extracted from the template, including title and content identifiers.
Returns
string The generated HTML content.
Run(HtmlEmailMetadata?, IDictionary<string, object?>)
HtmlEmailTemplate.csRuns the template with named parameters and returns the generated HTML along with extracted metadata.
public virtual string Run(out HtmlEmailMetadata? metadata, IDictionary<string, object?> parameters)Parameters
metadataHtmlEmailMetadata?- Receives metadata extracted from the template, including title and content identifiers.
parametersIDictionary<string, object?>- Named parameters to pass to the template.
Returns
string The generated HTML content.
Run(HtmlEmailMetadata?, object?[])
HtmlEmailTemplate.csRuns the template with positional parameters and returns the generated HTML along with extracted metadata.
public virtual string Run(out HtmlEmailMetadata? metadata, params object?[] parameters)Parameters
metadataHtmlEmailMetadata?- Receives metadata extracted from the template, including title and content identifiers.
parametersobject?[]- Positional parameters to pass to the template.
Returns
string The generated HTML content.
Run(TextWriter, HtmlEmailMetadata?)
HtmlEmailTemplate.csRuns the template without parameters and writes the generated HTML to the specified writer.
public virtual void Run(TextWriter writer, out HtmlEmailMetadata? metadata)Parameters
writerTextWriter- The text writer to write the generated HTML to.
metadataHtmlEmailMetadata?- Receives metadata extracted from the template, including title and content identifiers.
Run(TextWriter, HtmlEmailMetadata?, IReadOnlyDictionary<string, object?>)
HtmlEmailTemplate.csRuns the template with named parameters and writes the generated HTML to the specified writer.
public virtual void Run(TextWriter writer, out HtmlEmailMetadata? metadata, IReadOnlyDictionary<string, object?> parameters)Parameters
writerTextWriter- The text writer to write the generated HTML to.
metadataHtmlEmailMetadata?- Receives metadata extracted from the template, including title and content identifiers.
parametersIReadOnlyDictionary<string, object?>- Named parameters to pass to the template.
Run(TextWriter, HtmlEmailMetadata?, object?[])
HtmlEmailTemplate.csRuns the template with positional parameters and writes the generated HTML to the specified writer.
public virtual void Run(TextWriter writer, out HtmlEmailMetadata? metadata, params object?[] parameters)Parameters
writerTextWriter- The text writer to write the generated HTML to.
metadataHtmlEmailMetadata?- Receives metadata extracted from the template, including title and content identifiers.
parametersobject?[]- Positional parameters to pass to the template.