Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.24k stars 214 forks source link

[Question] How to pass boolean values from helper to template #589

Open kal800 opened 2 weeks ago

kal800 commented 2 weeks ago

I've got a HTML template which should apply certain content based on the language version. For "pl-PL" a polish version and for any other english. Now, I'm passing language parameter in report request. I've written simple handlebars helper:

 Handlebars.RegisterHelper("IsPolish", (writer, context, parameters) =>
    {
        if (req.Lang == "pl-PL")
           writer.WriteSafeString(true);
        else writer.WriteSafeString(false);
    });

The helper returns correct value, but Handlebars does not interpret it correctly:

    <td style="width:35%">{{IsPolish}}</td>
    <td style="width:15%">{{#if (IsPolish)}}TRUE{{else}}FALSE{{/if}}</td>

After rendering it shows:

<td style="width:35%">False</td>
<td style="width:15%">TRUE</td>

From what I've read, the Handlebars is case sensitive and .net serializes boolean values with first capital letter first, but I do not have a clue how to overcome it.