Can you recommend the .net template engine?

I'm looking for a .net template modeling engine - something simple, easy, stable with not too many dependencies. All I need now is the creation of template text and html messages. Can someone give me a good recommendation?

If that helps at all - something like Java Freemarker or Velocity .

[UPDATE] Thanks for the answers so far - much appreciated. I am really interested in recommendations or war stories when you used these libraries. This seems to be the best way to make a decision without trying each in turn.

+48
templates templating-engine
Dec 04 '08 at 10:06
source share
15 answers

Here are a couple more:

About NVelocity, it was forked by the castle guys, it is being developed here

For emails, I never need more than NVelocity.

+22
Dec 04 '08 at 11:15
source share

More complete list

  • ASP.Net built-in WebForm viewer
  • ASPView
  • Braille
  • NHaml (.Net port of Hamla)
  • Spark
  • NVelocity
  • StringTemplate.Net
+5
Mar 05 '09 at 7:43
source share

I would recommend the CodeSmith Generator . It is a template-based code generator with constant updates and an active community. Here is a list of templates that come with the CodeSmith generator.

+5
Feb 05 2018-11-21T00:
source share

RazorEngine, a template engine built on the Microsoft Razor parsing engine.

https://github.com/Antaris/RazorEngine

I haven’t used it, but I find it interesting, because if you have an ASP.NET MVC background, you won’t need to learn anything new.

+5
Mar 14 '14 at 15:57
source share

string template from people anltr.org with c # version too .

+3
Dec 04 '08 at 11:37
source share

I just released an open source project. It focuses mainly on email templates, but you can use the parser yourself if you want. You can read more information and get the source code from my blog.

http://thecodedecanter.wordpress.com/2010/07/19/town-crier-an-open-source-e-mail-templating-engine-for-net/

+2
Jul 20 '10 at 0:24
source share

I think Mustache (http://mustache.github.com/) can fit in the bill.

+2
Jun 26 2018-12-12T00:
source share

Some tests with Handlebars, RazorEngine and SharpTAL below:

namespace ConsoleApplication4 { class Program { static void Main(string[] args) { Stopwatch sw = new Stopwatch(); //RAZOR string razorTemplate = @"@model ConsoleApplication4.Test <h1>@Model.Title</h1> @if(Model.Condition1) { <span>condition1 is true</span> } <div> @foreach(var movie in Model.Movies) {<span>@movie</span>} </div>"; //burning Engine.Razor.RunCompile(razorTemplate, "templateKey", typeof(Test), new Test()); sw.Start(); var result1 = Engine.Razor.RunCompile(razorTemplate, "templateKey", typeof(Test), new Test()); sw.Stop(); Console.WriteLine("razor : "+sw.Elapsed); //SHARPTAL string sharpTalTemplate = @"<h1>${Title}</h1> <span tal:condition=""Condition1"">condition1 is true</span> <div tal:repeat='movie Movies'>${movie}</div>"; var test = new Test(); var globals = new Dictionary<string, object> { { "Movies", new List<string> {test.Movies[0],test.Movies[1],test.Movies[2] } }, { "Condition1", test.Condition1 }, { "Title", test.Title }, }; var tt = new Template(sharpTalTemplate); tt.Render(globals); sw.Restart(); var tt2 = new Template(sharpTalTemplate); var result2 = tt2.Render(globals); sw.Stop(); Console.WriteLine("sharptal : " + sw.Elapsed); //HANDLEBARS string handleBarsTemplate = @"<h1>{{Title}}</h1> {{#if Condition1}} <span>condition1 is true</span> {{/if}} <div> {{#each Movies}} <span>{{this}}</span> {{/each}} </div>"; var tt3 = Handlebars.Compile(handleBarsTemplate); sw.Restart(); var result3 = tt3(new Test()); sw.Stop(); Console.WriteLine("handlebars : " + sw.Elapsed); Console.WriteLine("-----------------------------"); Console.WriteLine(result1); Console.WriteLine(result2); Console.WriteLine(result3); Console.ReadLine(); } } public class Test { public bool Condition1 { get; set; } public List<string> Movies { get; set; } public string Title { get; set; } public Test() { Condition1 = true; Movies = new List<string>() { "Rocky", "The Fifth Element", "Intouchables" }; Title = "Hi stackoverflow! Below you can find good movie list! Have a good day."; } } } 

and results:

code results

+2
Nov 05 '15 at 14:18
source share

try the following: Email Template Structure http://www.bitethebullet.co.uk/Email_Template_Framework.aspx

It works fine under ASP.NET and WinForms and is still under active development. There is also very good documentation and is easy to dig in the examples.

+1
Apr 22 '11 at 2:28
source share

DotLiquid is a very nice .NET template system.

It is obtained from Rubys Liquid Markup with the requirements of the .NET Framework 3.5 or higher.

+1
Jun 03 '14 at 15:34
source share

Have you seen NVelocity, the .NET Velocity port? http://nvelocity.sourceforge.net/

0
Dec 04 '08 at 10:11
source share
0
Dec 04 '08 at 10:49
source share

NVELOCITY, although it is old, the last release in 2003, is enough.

0
May 20 '13 at 3:14
source share

SharpTAL - standalone engine in active development and without dependencies, fast

0
Apr 04 '14 at 19:47
source share

XCST (eXtensible C-Sharp Templates)

 <ul> <c:for-each name='n' in='System.Linq.Enumerable.Range(1, 5)' expand-text='yes'> <li>{n}</li> </c:for-each> </ul> 
0
Oct 29 '17 at 0:32
source share



All Articles