ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

Helpers do not load (sometimes) #271

Open DjovDev opened 4 years ago

DjovDev commented 4 years ago

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 commented 4 years ago

Nothing? Is this project dead? :/

UziTech commented 4 years ago

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.

DjovDev commented 4 years ago

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

nknapp commented 4 years ago

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.