質問

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

What I want to do is is something like this.

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

And use it in a doT.js template like this:

{{xyz(2,5)}}
役に立ちましたか?

解決

You can do so by using some of the advanced features of doT.js, see their advanced snippets examples for other advanced use.

This is how to defined a function to be used

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

And this execute it.

{{#def.fntest()}}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top