Reputation: 3475
I'm just getting into Sails.js and was wondering if there was a way with the EJS templating system to have a helper function run which includes a promise or database query. This works:
in config/http.js:
module.exports.http = {
// ...
locals: {
filters: {
testHelper: function(input) { return input; }
}
}
}
This does not:
module.exports.http = {
// ...
locals: {
filters: {
testHelper: function(input) {
MyModal.create({test:'test'}).exec(function(err,mm){
return input+'-'+mm.test;
});
}
}
}
}
The first always returns "check", the second always returns "undefined" when used in a template "{{ 'check' | testHelper }}"
Upvotes: 1
Views: 278