How to output block with handlebars dot net conditional helper?

試著忘記壹切 提交于 2020-01-05 07:14:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!