The solution is pretty simple.
Handlebars will return the properties of the object that you pass to the templates, if the property is a function , it will execute this function and display the return value
In your example, the function does not return any value (it just causes a warning), so the output is empty.
You can create a helper method like this:
handlebars.registerHelper('stringifyFunc', function(fn) { return new Handlebars.SafeString("(" + fn.toString().replace(/\"/g,"'") + ")()"); });
Then, from within the template, you just need to use it for a function that needs to be compressed:
<div id="divTemplate"> <span onclick="{{stringifyFunc func}}">{{text}}</span> </div>
source share