Global helper functions in doT.js templates

I want to define and use a global helper function for the doT.js template mechanism , how can I do this?

What I want to do is something like this.

var xyz = function(p1, p2) { return p1 + p2; }

And use it in the doT.js template as follows:

{{xyz(2,5)}}
+4
source share
1 answer

You can do this using some of the extended doT.js functions, see their extended snippet examples for other advanced uses.

Here's how to determine which function to use.

{{##def.fntest = function() {
    return "Function test worked!";
}
#}}

And that will fulfill it.

{{#def.fntest()}}
+3
source

Source: https://habr.com/ru/post/1535563/


All Articles