Helpers do not load (sometimes)
I have a really frustrating issue, I can't seem to reproduce.
But sometimes my helpers don't seem to load. I get all kinds of errors on pages including these global helpers e.g. "Helper isequal not defined" and the whole page goes into failrue.
I define my engine as such:
var app = express();
app.set("view engine", "handlebars");
var helpers = require("./views/helpers/handlebars");
var hbs = exphbs.create({
defaultLayout: "main",
helpers: helpers
});
app.engine("handlebars", hbs.engine);
My helper code goes as follows:
var moment = require('moment')
//helps pick value in select
exports.select = function(selected, options) {
return options.fn(this).replace(
new RegExp(' value=\"' + selected + '\"'),'$& selected="selected"');
}
//check if values are the same
exports.isequal = function (arg1, arg2, options) {
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
}
//formats date object as DD/MM/YYYY
exports.ddmmyyyy = function (date,options) {
if (moment(date)) {
return moment(date).format('DD/MM/YYYY')
} else {
return "Invalid date"
}
}
//formats date object as DD/MM/YYYY hh:mm:ss
exports.timestamp = function(date,options) {
if (moment(date)) {
return moment(date).format('DD/MM/YYYY HH:mm:ss')
} else {
return "Invalid date"
}
}
I am not sure if this is a bug, or something that I'm doing wrong.
Nothing? Is this project dead? :/
pretty much. It looks like this was developed by Yahoo employees that have since moved on. @sahat was the last one I know that was active but according to his contribution graph he seems to have dropped off of GitHub.
That's a bummer. I have many projects running on this.
If I can believe the NPM statistics, 100.000 other (weekly) projects do as well. Oh well, might have to jump on the hype train and learn react then...
I think https://github.com/barc/express-hbs does almost the same, in the same way. Might be easy to migrate. I don't know it if it more active though.