ericf / express-handlebars

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

Missing helper that is not missing #173

Open justinledouxweb opened 8 years ago

justinledouxweb commented 8 years ago

Hi,

I am building a small tool that allows me to view a questionnaire in the browser, and then download the HTML file for offline viewing.

When I visit the questionnaire's page in a route handler that is using res.render(), it works perfectly:

    app.get( '/victim-questionnaire', ( req, res ) => {
        res.render( 'victim-questionnaire', {
            pageTitle:      'Victim Questionnaire',
            formSections: require( './data/victim-questionnaire.json' ).sections
        })
    })

But when I compile the files for download, my non-missing help is missing:

(by the way handlebarsConfig.handlebars contains the helpers. If I console.log( hdb ) you can see the custom helpers there in the object).

    app.get( '/download/:fileName', function ( req, res ) {
        var hdb = handlebars.create( handlebarsConfig.handlebars )

        var data = fs.readFileSync( 'data/' + req.params.fileName + '.json', 'utf8' ),
                data = JSON.parse( data )

        var bodyHtml = fs.readFileSync( 'views/' + req.params.fileName + '.handlebars', 'utf8' )
                bodyHtml = hdb.handlebars.compile( bodyHtml )
                bodyHtml = bodyHtml({
                    formSections: data.sections
                })

        var template = fs.readFileSync( 'views/layouts/main.handlebars', 'utf8' )
                template = hdb.handlebars.compile( template ),
                template = template({
                    pageTitle:  formManifest.forms[ req.params.fileName ].title,
                    mainCss:        mainCss,
                    printCss:   printCss,
                    bodyHtml:   bodyHtml
                })

        res.attachment( 'temp/' + req.params.fileName + '.html' )
        res.setHeader( 'Content-Type', 'text/html' )
        res.end( template )
    })

What is VERY weird, is that it was working fine yesterday, and now it's not... nothing has changed (damn computer ghosts!!)

DjovDev commented 4 years ago

Hello

I have the same issue here!

I created a custom helper called "isequal" like so:

var hbs = exphbs.create({
    defaultLayout: 'main',
    helpers: {
        isequal: function (arg1, arg2, options) {
            return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
        }
    }
})

I am getting this error message (at random times) Error: Missing helper: "isequal"

I have already tried rebooting the server app every 24h but to no avail.