Created
March 6, 2014 10:28
-
-
Save JohanObrink/9386961 to your computer and use it in GitHub Desktop.
Revisions
-
JohanObrink created this gist
Mar 6, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ using Nustache.Core; using System; using System.IO; using System.Text; public static class TemplateExtensions { public static Template Load(this Template template, string html) { using (var reader = new StringReader(html)) { template.Load(reader); } return template; } public static string Render(this Template template, object data) { var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { template.Render(data, writer, null); } return sb.ToString(); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ using Nustache.Core; using System; using System.IO; using System.Text; using System.Web.Mvc; namespace HtmlMail.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { var html = "<!doctype html><html><head></head><body><h1>{{headline}}</h1>{{#msg}}<p>{{message}}</p>{{/msg}}</body></html>"; var template = new Template().Load(html); ViewBag.Html = template.Render(new { headline = "Hello World!", message = "Iz nize!", msg = true }); return View(); } } }