Skip to content

Instantly share code, notes, and snippets.

@TechWatching
Created March 9, 2019 15:27
Show Gist options
  • Save TechWatching/14bc3bba36aafefb364d4c89d7570c90 to your computer and use it in GitHub Desktop.
Save TechWatching/14bc3bba36aafefb364d4c89d7570c90 to your computer and use it in GitHub Desktop.
C# script that use the Handlebars.Net library to do HTML templating
#r "nuget: Handlebars.Net, 1.9.5"
using HandlebarsDotNet;
string html = @"
<ul class=""people"">
{{#each people}}
<li>{{FirstName}} {{LastName}} - {{Job}}</li>
{{/each}}
</ul>";
var data = new
{
people = new []
{
new { FirstName = "Ellana", LastName = "Caldin", Job = "Marchombre"},
new { FirstName = "Edwin", LastName = "Til'Illan", Job = "General"}
}
};
var template = Handlebars.Compile(html);
string result = template(data);
Console.WriteLine(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment