+1 vote

Hi there!

Is there a list of available commands / switches for your email template engine?

Thank you very much!
Mike Hachen

by (250 points)

1 Answer

0 votes

You can use if, foreach and any public field, property or method there is on the view model class. You can also specify format string for each field:

Hi [Buyer.FirstName] [Buyer.LastName],

On [PurchaseDate:yyyy/MM/dd HH:mm] you purchased following items:

[foreach OrderItems]
   - [Id] [Name] [Price]

Free shipment: [if FreeShipment]Yes[else]No[end].

\[ escaped square brackets \]

Method: [Buyer.GetFullName]

We expect ViewModel classes to contain all logic, so it can be easily unit tested:

 public class Contact
     public string FirstName { get; set; }
     public string LastName

     public string GetFullName()
         return this.FirstName + " " + this.LastName;

 public class Order
     public Contact Buyer { get; set; }
     public List<Items> OrderItems { get; private set; }

     public bool FreeShipment;

And finally template rendering:

string templateBody = "...";
Order order = ...;

Template template = Template.Create(templateBody).DataFrom(order);

string rendered = template.Render();

Finally you can also put some data in a dictionary:

string s = Template.Create("Show some number [key].")
    .AddKey("key", "42")
by (297k points)