Skip to content

Formatting Capabilities

Norbert Bietsch edited this page Dec 7, 2018 · 4 revisions

The {placeholders} and the formatting capabilities allows separation of code and design. In order to change the content of an email just change the template file(s) for the plain or HTML text and you're done without a need to touch your code, as long as the data source is the same.

Generally, formatting of {placeholders} is fully compatible with string.Format by means of SmartFormat.Net which is a dependency of MailMergeLib. SmartFormat.Net has a lot of extensions which go far beyond string.Format. This project is also maintained by axuno.

For details please refer to the SmartFormat Wiki.

Note The MailMergeMessage.SmartFormatter is responsible for configuring SmartFormat.Net in the way MailMergeLib makes use of it.

Simple format string examples:

  • variable of type DateTime: "{Date:yyyy-MM-dd}"
  • variable of type int: "You are visitor number {NumOfVisitors}"
  • variable which is an instance of class "user": "{Name} from {Address.City}, {Address.State}"

Extended format string examples:

  • Pluralization: "You have {emails.Count} new {emails.Count:message|messages}"
  • Conditional ("Enabled" is a boolean): "Backup enabled? {Enabled:Yes|No}"
  • A list (of users): "{Users:{Name}|, |, and } liked your comment"
  • An object with property "Name" which can be null, empty or a string"{Name:choose(null|):N/A|empty|{Name}}"