Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've had to do this on a couple of occasions. I originally used the ASP.Net template engine based on I think a Rick Strahl blog post. It worked but there was always some issue I was banging my head against.</p> <p>I switched to using the <a href="http://www.castleproject.org/others/nvelocity/index.html" rel="nofollow noreferrer">NVelocity</a> template engine and found it a really simple way to create and maintain email templates. There are a number of other template engines and I suspect next time I might have a serious look at the <a href="https://stackoverflow.com/questions/4368815/razor-views-as-email-templates">Razor</a> <a href="http://kazimanzurrashid.com/posts/use-razor-for-email-template-outside-asp-dot-net-mvc" rel="nofollow noreferrer">engine</a>.</p> <p>The code for merging values into the template:</p> <pre><code>private string Merge(ManualTypeEnum manualType, Object mergeValues) { var body = ""; var templateFile = string.Format("{0}MailTemplate.vm", manualType); var velocity = new VelocityEngine(); var props = new ExtendedProperties(); props.AddProperty("file.resource.loader.path", Config.EmailTemplatePath); velocity.Init(props); var template = velocity.GetTemplate(templateFile); var context = new VelocityContext(); context.Put("Change", mergeValues); using (var writer = new StringWriter()) { template.Merge(context, writer); body = writer.ToString(); } return body; } </code></pre> <p>The values to merge are passed as an anonymous object, and can include various types including lists etc e.g.</p> <pre><code>var emailBody = Merge(newDocument.ManualType, new { ManualType = newDocument.ManualType.ToString(), Message = change.Message, NewTitle = newDocument.Title ?? "", NewVersion = newDocument.Version ?? "", Contact = From, Changes = change.ToList(), }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload