How to output block with handlebars dot net conditional helper?

1k views Asked by At

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

There are 1 answers

0
xaisoft On

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);
            }

        });