Skip to content

Instantly share code, notes, and snippets.

@jesulink2514
Created January 4, 2016 22:38
Show Gist options
  • Save jesulink2514/e68a322e740b4a537de9 to your computer and use it in GitHub Desktop.
Save jesulink2514/e68a322e740b4a537de9 to your computer and use it in GitHub Desktop.
MailGenerator para Handlerbars y generación de correo
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