2

I am using express handlebars as templating engine in node js. i have written helpers for handlebars in app.js. How can i pass parameters to these helpers from hbs file.

   helpers: {
    ifCondition : function (value, value2) {
        if(value == value2){
            return "selected";
        }else{
            return value + '/ '+ value2;
        }
    },
    formatNumber : function (number, limit){
        var formattedNum = number.toString().replace(/[^0-9.]/g, "");
        formattedNum = formattedNum.replace(/(\r\n|\n|\r)/gm," ");
        formattedNum = formattedNum.replace(/\s+/g," ");

        if(formattedNum){
            return formattedNum = '00971'+ formattedNum.substring(formattedNum.length-limit, formattedNum.length);
        }else{
            return '---';
        }
    }

},

1 Answer 1

2

Try to helper like this.

{{ helpername parameter1 parameter2}}
1
  • can we add function as parameter?? Sep 19, 2018 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.