添加插件到ejs?

我怎么能把我自己的自定义函数添加到ejs?

<%- custom_function('test') %> 

谢谢!

您可以将自己的filter添加到ejs。

 ejs.filters.custom_function = function(str) { return str + ' custom string'; }; 

在模板中,您可以像这样访问您的filter:

 <%=: 'somestring' | custom_function %> 

您可以使用冒号将其他parameter passing给您的函数。

 ejs.filters.custom_function = function(str, postfix) { return str + postfix; }; 

并在您的模板中:

 <%=: 'somestring' | custom_function:' custom postfix' %>