2012-03-05 37 views

回答

2

您可以将自己的过滤器添加到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' %>