i have 2 type of value on handlebar page , needs compare first 1 second. can print value of following code
{{articledetails.content_writer_id}}
before writing each loop on page. want compare value following. can not scope of articledetails.content_writer_id in below code.
{{#each contentwriterdetails}} {{#compare this.id "==" articledetails.content_writer_id }}
i have registered compare helper using code.
handlebars.registerhelper('compare', function (lvalue, operator, rvalue, options) { var operators, result; if (arguments.length < 3) { throw new error("handlerbars helper 'compare' needs 2 parameters"); } if (options === undefined) { options = rvalue; rvalue = operator; operator = "==="; } operators = { '==': function (l, r) { return l == r; }, '===': function (l, r) { return l === r; }, '!=': function (l, r) { return l != r; }, '!==': function (l, r) { return l !== r; }, '<': function (l, r) { return l < r; }, '>': function (l, r) { return l > r; }, '<=': function (l, r) { return l <= r; }, '>=': function (l, r) { return l >= r; }, 'typeof': function (l, r) { return typeof l == r; } }; if (!operators[operator]) { throw new error("handlerbars helper 'compare' doesn't know operator " + operator); } result = operators[operator](lvalue, rvalue); if (result) { return options.fn(this); } else { return options.inverse(this); } });
and above helper working fine have checked that.
any appreciated.
use parent's context path:
{{#each contentwriterdetails}} {{#compare this.id "==" ../articledetails.content_writer_id }}
Comments
Post a Comment