Project Description SharpTemplate.NET is a lightweight general-purpose template engine for .NET 2.0. It is very easy to use, yet very powerful. It supports a pluggable syntax, full C# compliant expression parser, caching and macros.
Features
- Template syntax is fully customizable (includes syntaxes for Velocity, ProMesh.NET)
- Loops (foreach)
- Conditionals (if - elseif - else)
- Late-bound C# expression evaluation (using LazyParser.NET, which is part of this project)
- Light-weight (less than 80KB)
Example of a template (using Velocity syntax):
<table>
#foreach ($product in $Products)
<tr><td>$product.Name</td>
#if ($product.Stock > 0)
<td>In stock</td>
#else
<td>Backordered</td>
#end
</tr>
#end
</table>
The same template in "ProMesh.NET" syntax:
<table>
<!--$[foreach product in Products]-->
<tr><td>$[product.Name]</td>
<!--$[if product.Stock > 0]-->
<td>In stock</td>
<!--$[else]-->
<td>Backordered</td>
<!--$[endif]-->
</tr>
<!--$[endfor]-->
</table>
The code to parse and render the template:
SharpTemplate template = new SharpTemplate<Velocity>();
ParserContext data = new CSharpContext();
data["Products"] = GetOrders();
string renderedFile = template.RenderFile("template.htm" , data);