Note that there are some explanatory texts on larger screens.

plurals
  1. PORazorEngine string layouts and sections?
    text
    copied!<p>I use razor engine like this:</p> <pre><code>public class EmailService : IService { private readonly ITemplateService templateService; public EmailService(ITemplateService templateService) { if (templateService == null) { throw new ArgumentNullException("templateService"); } this.templateService = templateService; } public string GetEmailTemplate(string templateName) { if (templateName == null) { throw new ArgumentNullException("templateName"); } Assembly assembly = Assembly.GetAssembly(typeof(EmailTemplate)); Stream stream = assembly.GetManifestResourceStream(typeof(EmailTemplate), "{0}.cshtml".FormatWith(templateName)); string template = stream.ReadFully(); return template; } public string GetEmailBody(string templateName, object model = null) { if (templateName == null) { throw new ArgumentNullException("templateName"); } string template = GetEmailTemplate(templateName); string emailBody = templateService.Parse(template, model, null, null); return emailBody; } } </code></pre> <p>The templating service I use is injected although it's just a default implementation:</p> <pre><code> internal ITemplateService InstanceDefaultTemplateService() { ITemplateServiceConfiguration configuration = new TemplateServiceConfiguration(); ITemplateService service = new TemplateService(configuration); return service; } </code></pre> <p>Since in this case in particular I will be building emails from these templates. I want to be able to use <code>@section</code>s for the email'a subject, and different sections of the email body, while using a layout where I specify the styles that are common to the whole email structure (which will look like one of <a href="http://mailchimp.com/resources/html-email-templates/">MailChimp</a>'s probably).</p> <p>The question is then twofold:</p> <ul> <li>How can I specify layouts in <code>RazorEngine</code>?</li> <li>How can I specify these layouts from strings (or a stream)? since as you can see, I use embedded resources to store the razor email templates.</li> </ul> <h1>Update</h1> <p>Maybe I wasn't clear, but I'm referring to the <a href="http://razorengine.codeplex.com/"><strong>RazorEngine</strong></a> library.</p>
 

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