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?
Declare a template in the HTML file. Handlebars expressions are put into double curly braces {{expr}} for HTML-escaped content; otherwise, use triple curly brackets {{{expr}}} to avoid HTML-escaping.
A Handlebars helper call is a simple identifier, followed by zero or more parameters (separated by a space). Each parameter is a Handlebars expression that is evaluated exactly the same way as described above in "Basic Usage": template {{firstname}} {{loud lastname}}
Any comments that must contain }} or other handlebars tokens should use the {{! -- --}} syntax.
Handlebars expressions may be used for: Mapping Export and Import application fields; Performing dynamic arithmetic calculations on the values being exported; Performing dynamic encoding and decoding of data during integration.
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.
})
jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With