Handlebars : What is the best way to pass multiple parameters to a registerHelper function?
14,572
Nope. As per their document you can do this in many ways. I would do this way.
{{getOutputByParameters param1 param2}}
Handlebars.registerHelper('getOutputByParameters', function(param1, param2){
//do your stuff here.
})
Comments
-
dhruvpatel almost 2 years
I am using Handlebars to render data in a table.
One of the data items needs processing, which takes a few parameters into account in order to provide outcome.
The templated text example :
{{getOutputByParameters param1=DataFieldName1 param2=DataFieldName2}}
And corresponding registerHelper would be written as:
var __this = this; Handlebars.registerHelper('getOutputByParameters', function(params){ __this.getOutputByParameters(params.hash.param1, params.hash.param2)})
I figured that handlebars would pass an array of these parameters, which I can access using hash property.
But is that the only best way?
-
dhruvpatel almost 11 yearsThanks for posting with jsFiddle, it's really awesome to see answer with demo -- live!!!
-
dhruvpatel over 9 yearsSorry @user10, I don't know why I didn't mark your reply as answer, but better late then never done.