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()}}