问题
I have the following helper for handlebars.net:
Handlebars.RegisterHelper("#is",
(writer, context, args) =>
{
string val1 = args[0].ToString();
string val2 = args[1].ToString();
if (val1 == val2)
{
//how to get block output
}
});
I am trying to test it on the following html, but I am not sure how to write out the content between {#is} and {/is}
if it is true:
<div style="text-align: right;">
{{#each TeamMembers}}
{{#is this.Title 'Manager'}}
{{ this.Name }}<br />
{{ this.PersonalEmail }}<br />
{{ this.Phone }}<br />
{{/is}}
{{/each}}
</div>
回答1:
Figured it out using a different signature:
Handlebars.RegisterHelper("is",
(writer,options, context, args) =>
{
string val1 = args[0].ToString();
string val2 = args[1].ToString();
if (val1 == val2)
{
options.Template(writer, (object)context);
}
});
来源:https://stackoverflow.com/questions/46243554/how-to-output-block-with-handlebars-dot-net-conditional-helper