独自のカスタム関数をejsに追加するにはどうすればよいですか?
<%- custom_function('test') %>
ありがとうございました!
独自のフィルターを ejs に追加できます。
ejs.filters.custom_function = function(str) {
return str + ' custom string';
};
テンプレートでは、次のようにフィルターにアクセスできます。
<%=: 'somestring' | custom_function %>
コロンを使用して、追加のパラメーターを関数に渡すことができます。
ejs.filters.custom_function = function(str, postfix) {
return str + postfix;
};
そしてあなたのテンプレートで:
<%=: 'somestring' | custom_function:' custom postfix' %>