-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRazorEngine-a-very-nice-text-template-engine-in-.Net.html.raw
More file actions
1 lines (1 loc) · 1.73 KB
/
RazorEngine-a-very-nice-text-template-engine-in-.Net.html.raw
File metadata and controls
1 lines (1 loc) · 1.73 KB
1
<p>RE is a templating engine based on Microsoft Razor parser, we can use Razor syntax to build our complex and beatiful document with very easy. It allows to start with all default configuration, but there are points that we should cusotmize to satisfy our need.</p><p>1/ Run vs RunCompile</p><p>Once the template (based on templateKey - must be unique value in our application) is already complied, we can just use Run to be faster.</p><p>But RunCompile will do the compile for us incase the template is run the first time. An example is simply as below:</p><blockquote> public string Transform(string template, string templateKey, object model)<br> {<br> return Engine.Razor.RunCompile(template, templateKey, null, model);<br> }</blockquote><div>2/ Create a custom configuration - if you want the output is raw Html</div><div>By default, RE geneated an encoded HTML output. When you need it to be raw HTML string (to display in an email, or let users to view on browser), it is able to customize. The below is a snippet for the need:</div><div><blockquote> var config = new TemplateServiceConfiguration<br> {<br> EncodedStringFactory = new RawStringFactory(),<br> };<br> Engine.Razor = RazorEngineService.Create(config);</blockquote></div><div><p><b><u><i>References:</i></u></b></p><ol><li><a href="https://github.com/Antaris/RazorEngine" target="_blank">RazorEngine source repo</a></li></ol></div>