I have created a custom ejs filter following this SO Question

I created the file in /config and added my filter:

var ejs = require('ejs');
var moment = require('moment');

ejs.filters.formatDate = function (date) {
    return moment.date(date).format('dd mm yy hh:ii');
};

ejs.open = '<?';
ejs.close = '?>';

However, when using the filter in the ejs template I get the error that formatDate is not defined. I am using like so:

<?= child.lastPost.createdAt | formatDate ?>

Anyone know where I went wrong?

有帮助吗?

解决方案

Apparently I needed to use a colon in the opening tag

<?=:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top