I’ve hit the need to be able to store templatized content separately from the code that generates the dynamic fields that fill that content (think mail merge in word). The use case generally revolves around the fact that I want to write code that can send out some type of dynamic content (often an email) which I want to allow my users to customize without changing any code.
For example, we send emails to our clients. We end up tweaking the emails that go out and adding dynamic content (i.e. for example we may want to say “Dear {Contact.FirstName},”). It’s convenient to throw the format of these emails into the database or some XML file and write the code that gives it the values of all the properties separately. So create an Email.XML with the content and an engine that takes that XML file passes it the Contact object and returns the HTML of the email. Conceptually this fairly similar to the goal of separating the view layer in the MVC pattern (the email is the view in this case, the engine is the controller and the Contact object is the model).
It looks like there’s two contenders in the .Net space (both ports of java) (there’s more here but they are fairly niche players).
- StringTemplate.Net
- NVelocity (original project, fork of the castle project)
Has anyone used either of these or other templatization engines? Are the key differences between them I should take into consideration when choosing