express-handlebars icon indicating copy to clipboard operation
express-handlebars copied to clipboard

Helpers do not load (sometimes)

Open DjovDev opened this issue 6 years ago • 4 comments

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.

DjovDev avatar Dec 30 '19 10:12 DjovDev

Nothing? Is this project dead? :/

DjovDev avatar Jan 08 '20 14:01 DjovDev

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.

UziTech avatar Jan 08 '20 17:01 UziTech

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...

DjovDev avatar Jan 10 '20 09:01 DjovDev

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.

nknapp avatar Jan 18 '20 21:01 nknapp