How to pass data with a 'function' as value to the template?
-
Say I got some data in function beforeRender like this:
req.data.myData = {
name: 'test',
formatter: function(value) {
return '$' + value;
}
}How can I get the function pass into the template?
-
hi @liwonder you can define those functions as helpers in your templates, and you can use the helpers inside your template, quick playground for demonstration: https://playground.jsreport.net/studio/workspace/BJP7eMYTe/6
-
Thanks for your reply and that make sense! But now the situation I am facing is that I got ten or more children templates which will probably use this same function in the future, so I should copy and paste ten times, this is clearly not a good solution. If I want to make some changes with the function in the future, that would be a unwise move. Thanks!
-
@liwonder i didn't know your use case, but nothing that
assets
extension can't solve, here you have the same example updated sharing helpers between templates -> https://playground.jsreport.net/studio/workspace/BJP7eMYTe/10
-
more info here https://jsreport.net/learn/assets if you are curious
-
Thanks! I will look up the 'assets'.