Program is written in c# .net
string mySource =
@"<table>
<tr>
<th>File Name</th>
<th>Error</th>
<th>Size</th>
<th>Date</th>
<th>Testing</th>
</tr>
{{#each entry}}
<tr>
<td>{{fname}}</td>
<td>{{error}}</td>
<td>{{size}}</td>
<td>{{data}}</td>
<td>test data</td>
</tr>
{{/each}}
</table>";
var json = @"[
{
""fname"": ""testFile1"",
""error"": ""true"",
""size"": 10,
""date"": ""02-15-2023""
},
{
""fname"": ""testFile2"",
""error"": ""false"",
""size"": 8,
""date"": ""01-15-2023""
},
{
""fname"": ""testFile3"",
""error"": ""true"",
""size"": 195,
""date"": ""08-23-2021""
}
]";
var plz = JsonConvert.DeserializeObject<List<TemplateParams>>(json);
var template = Handlebars.Compile(mySource);
var result = template(plz);
As far as I can tell this should work but the program seems to think there is nothing in the list. The only thing that prints are the headers that are hard coded in, and other than that nothing prints.
If anyone has any ideas please let me know
I've tried changing the templates and the objects I am passing into the templates, but I keep getting only the headers to print.
The start of your
eachloop looks like this:The model that you provide to the rendering engine is just a collection, it doesn't have a property
entry. Usethisinstead.This means that you want to loop over the whole model - the
plzvariable you provide totemplate(), which is of typeList<TemplateParams>- rather than a non-existent property of the List object.