문제

We're looking for a fast, flexible way of generating templated content (in this case personalized e-mails in text and HTML format) from a .NET console application.

We have no VirtualPathProvider and no valid HttpContext.Current, which, from our initial experiments, means it's going to be very, very hard to use the WebForms view engine, and any of the other .NET web view engines (Spark, Razor) are going to need extensive plumbing to make them think they're running in a web app.

I want to do something like:

var customerTemplateData = GetTemplateDate(customer);
var htmlBody = templateEngine.Render("template.html", customerTemplateData);
var textBody = templateEngine.Render("template.txt", customerTemplateDate);
SendMail("me@mydomain.com", customer.Email, "Hey there!", htmlBody, textBody);

and I want to do it with complex nested data, lots of lists inside lists, up to 1,000 times a minute.

Any recommendations for dedicated template engines or for ways to run the Web view engines in a standalone context would be most appreciated :)

Thanks,

Dylan

도움이 되었습니까?

해결책

If you're looking for some guidance on how you'd achieve this with Spark, there is a fully functional Email and Text Templating Sample available here in the Spark source code.

It should be noted that there is actually no dependency that this sample has on HttpContext or any other web infrastructure for that matter. It's completely independant and could just as easily run as a console application.

Hope this helps,
All the best,
Rob

다른 팁

There are quite a few ways of creating templated content from the command line, NVelocity is an example, but also recently we're released our wrapper of the Razor parser on CodePlex ( http://razorengine.codeplex.com/ ) which I think is worth a look into.

Yet another, StringTemplate Template Engine.

However, I am attention to RezorTemplateEngine!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top