Created
January 4, 2016 22:38
-
-
Save jesulink2514/e68a322e740b4a537de9 to your computer and use it in GitHub Desktop.
MailGenerator para Handlerbars y generación de correo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Web; | |
using HandlebarsDotNet; | |
namespace WcfDemoMail.Mail | |
{ | |
public static class MailGenerator | |
{ | |
public static string TemplateFolder = "~/templates"; | |
public static string GetHtml<T>(T data,string templateName) | |
{ | |
var basePath = System.Web.Hosting.HostingEnvironment.MapPath(TemplateFolder); | |
var totalPath = Path.Combine(basePath, templateName); | |
if (!File.Exists(totalPath)) | |
throw new InvalidOperationException("La plantilla {0} no se ha encontrado en el folder de plantillas."); | |
var templateText = File.ReadAllText(totalPath); | |
var template = Handlebars.Compile(templateText); | |
var result = template(data); | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment