I have a template that looks like this: (I removed some elements of the table just to keep the code short)
{{#each Tables}}
<div id='report-container'>
<table id='report-table'>
<tr class='header-row'>
<th style='width: 150px; max-width: 150px !important;'>{{this.Title}}</th>
<th>Total Company Net Sales $</th>
...
</tr>
{{#each this.Data}}
<tr>
<td>{{RowTitle}}</td>
<td>{{currency TotalCompanyNetSales}}</td>
...
</tr>
{{/each}}
</table>
</div>
{{/each}}
With a helper:
handleBars.RegisterHelper("currency", (writer, context, parameters) =>
{
var value = decimal.Parse(parameters[0].ToString());
value /= 1000;
var result = value.ToString("0,-28:C2");
return result;
});
Im not sure if the object itself is relevant but I can post if necessary. The problem is just with the helper. When I try to compile the template I get the following error message:
"Reached end of template before block expression 'currency' was closed"
If I remove the currency helper the value displays fine. It never even calls the currency function. Any idea what I am doing wrong here?
The problem is related to a misuse of new (to Handlebars.Net) return helper
syntax: helper you're declaring is actually a block
helper returning value:
handleBars.RegisterHelper("currency", (writer /*this is not `writer` but `options`*/, context, parameters) =>
{
// your code here
return result; // change is caused by the `return` statement
});
In order to fix the helper and still use return
feature you should simply drop the options
argument from lambda:
handleBars.RegisterHelper("currency", (context, parameters) =>
{
// your code here
return result;
});